首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >JavaScript正则表达式解释?

JavaScript正则表达式解释?
EN

Stack Overflow用户
提问于 2018-06-26 05:55:33
回答 1查看 0关注 0票数 0
代码语言:javascript
复制
/(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/

我在JavaScript中找到的这个表达式检查URL验证。

有人可以解释它是如何工作的吗?

EN

回答 1

Stack Overflow用户

发布于 2018-06-26 15:16:56

说明:

代码语言:javascript
复制
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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/-100005525

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档