简体   繁体   English

为什么正则表达式不能捕获'www。'

[英]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.comhttp://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.

相关问题 为什么惰性正则表达式会捕获多余的单词? - Why does lazy regex capture extra words? 为什么正则表达式(。*?(?: *?\\ n))捕获换行符? - Why does the regex (.*?(?: *?\n)) capture newlines? 为什么正则表达式不能捕获最初的单词? 蟒蛇 - Why does the regex not capture the initial word? Python 如何使用python正则表达式删除忽略www。 并只提供域名? - How to use python regex to remove ignore www. and only give the domain name? 为什么捕获使用此正则表达式搜索模式标识的捕获组失败? - Why does capturing the capture group identified with this regex search pattern fail? 为什么在第一个捕获组再次出现之前,此正则表达式不匹配所有内容? - Why does this regex not match everything till recurrence of first capture group? 为什么此正则表达式最多捕获 2 个捕获组而不是输入字符串中的所有捕获组? - Why does this regex capture a maximum of 2 capture groups and not all those within the input string? 为什么这个正则表达式没有在空格之前捕获? - why this regex is not capture before space? 正则表达式不捕获公寓、套房、单元号 - Regex does not capture the apartment, suite, unit number 如何添加'www。' 到一些数据帧值的开头? - How to add 'www.' to the beginning of some dataframe values?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM