[英]Why does the regex not capture 'www.'
I'm creating a simple (I thought it would be simple) regex expression to capture ulr information in groups. 我正在创建一个简单的(我认为这很简单)正则表达式来捕获组中的ulr信息。 Everything lines up except when I use a web address that has 'www.'
除非我使用带有“www”的网址,否则一切都会排好。
Expression: 表达:
((https?):\/\/(?:www\.)?([\w\.\-\:]+)\/(.+))
Test URLs: 测试网址:
http://11.111.111.1:1010/nexus-2.3.1/service/local/artifact/maven/content?r=fake_release&g=com.fake&a=com.rake.fake.soap.webapp&v=LATEST&e=war
https://hello-ci.fake-re.com/jenkins/view/RAS/job/RAS_Designtime_Master/site/com.rake.fake.ras.documentation/kwl/Assessment-faker-gage.html
https://regex101.com/#python
https://www.google.com
http://www.apple.com
Why do I not get a match on https://www.google.com
nor http://www.apple.com
为什么我在
https://www.google.com
和http://www.apple.com
上都没有匹配
Note: This regular expression is for a python application 注意:此正则表达式适用于python应用程序
Those URLs are not matched because of the obligatory /
. 由于强制性
/
这些URL不匹配。 Make that part optional with a non-capturing group and ?
使用非捕获组使该部分可选并且
?
quantifier: 量词:
((https?):\/\/(?:www\.)?([\w\.\-\:]+)(?:\/(.+))?)
^^^ ^^
See regex demo 请参阅正则表达式演示
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.