/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/
我在JavaScript中找到的这个表达式检查URL验证。
有人可以解释它是如何工作的吗?
发布于 2018-06-26 15:16:56
说明:
1st Capturing Group (ftp|http|https)
1st Alternative ftp
ftp matches the characters ftp literally (case sensitive)
2nd Alternative http
http matches the characters http literally (case sensitive)
3rd Alternative https
https matches the characters https literally (case sensitive)
: matches the character : literally (case sensitive)
\/ matches the character / literally (case sensitive)
\/ matches the character / literally (case sensitive)
2nd Capturing Group (\w+:{0,1}\w*@)?
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)
\w+ matches any word character (equal to [a-zA-Z0-9_])
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
:{0,1} matches the character : literally (case sensitive)
{0,1} Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)
\w* matches any word character (equal to [a-zA-Z0-9_])
@ matches the character @ literally (case sensitive)
3rd Capturing Group (\S+)
\S+ matches any non-whitespace character (equal to [^\r\n\t\f\v ])
+ Quantifier — Matches between one and unlimited times, as many times as possible, giving back as needed (greedy)
4th Capturing Group (:[0-9]+)?
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)
: matches the character : literally (case sensitive)
Match a single character present in the list below [0-9]+
5th Capturing Group (\/|\/([\w#!:.?+=&%@!-\/]))?
? Quantifier — Matches between zero and one times, as many times as possible, giving back as needed (greedy)
1st Alternative \/
2nd Alternative \/([\w#!:.?+=&%@!-\/])
Global pattern flags
g modifier: global. All matches (don't return after first match)
m modifier: multi line. Causes ^ and $ to match the begin/end of each line (not only begin/end of string)
https://stackoverflow.com/questions/-100005525
复制相似问题