如何创建可以检查以下内容的正则表达式:
yAxis: {
...
zIndex: 4
}
或http
https
或不是www
,steamcommunity
必须有.com
或id
,后跟数字或文字
http://steamcommunity.com/id/rasmusvejby/ http://steamcommunity.com/profiles/76561198040893433
还应该说,如果它包含ID,它应该检查是否有文本,如果它同意配置文件,我应该检查数字。
答案 0 :(得分:1)
鉴于您的示例文本......
http://steamcommunity.com/id/rasmusvejby/
http://steamcommunity.com/profiles/76561198040893433
......这个正则表达式......
^https?://(?:www\.)?steamcommunity\.com/(id/([^/\s]*)|profiles/([^/\s]*))
...将执行以下操作
steamcommunity.com
www
http
或https
捕获群组
示例匹配
[0][0] = http://steamcommunity.com/id/rasmusvejby
[0][1] = id/rasmusvejby
[0][2] = rasmusvejby
[0][3] =
[1][0] = http://steamcommunity.com/profiles/76561198040893433
[1][1] = profiles/76561198040893433
[1][2] =
[1][3] = 76561198040893433
NODE EXPLANATION
----------------------------------------------------------------------
^ the beginning of a "line"
----------------------------------------------------------------------
http 'http'
----------------------------------------------------------------------
s? with or without 's'
----------------------------------------------------------------------
:// '://'
----------------------------------------------------------------------
(?: group, but do not capture (optional
(matching the most amount possible)):
----------------------------------------------------------------------
www 'www'
----------------------------------------------------------------------
\. '.'
----------------------------------------------------------------------
)? end of grouping
----------------------------------------------------------------------
steamcommunity 'steamcommunity'
----------------------------------------------------------------------
\. '.'
----------------------------------------------------------------------
com/ 'com/'
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
id/ 'id/'
----------------------------------------------------------------------
( group and capture to \2:
----------------------------------------------------------------------
[^/\s]* any character except: '/', whitespace
(\n, \r, \t, \f, and " ") (0 or more
times (matching the most amount
possible))
----------------------------------------------------------------------
) end of \2
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
profiles/ 'profiles/'
----------------------------------------------------------------------
( group and capture to \3:
----------------------------------------------------------------------
[^/\s]* any character except: '/', whitespace
(\n, \r, \t, \f, and " ") (0 or more
times (matching the most amount
possible))
----------------------------------------------------------------------
) end of \3
----------------------------------------------------------------------
) end of \1