如何从Notepad ++中提取URL的2级?

时间:2014-12-16 03:38:10

标签: regex url notepad++

这是一些网址:

http://www.mywebsite.com/name1-name2-name3-name4-342/46547657/ca
http://www.mywebsite.com/name5-487659826/da
http://www.mywebsite.com/name6-name7-567/5677/ca
http://www.mywebsite.com/name8-name9-name10-48765766/da
http://www.mywebsite.com/name11-name12-name13-name14-name15/11117657/ca
http://www.mywebsite.com/name16-4866626/da

因此,输出将是:

name1-name2-name3-name4-342
name5
name6-name7-567
name8-name9-name10
name11-name12-name13-name14-name15
name16

你能给我一个正则表达式吗?

2 个答案:

答案 0 :(得分:2)

对于您提供的给定网址,您可以使用以下内容来提取想要的子字符串。

http://[^/]+/\K\w+(?:-(?!\d{4,})\w+)*

Live Demo

答案 1 :(得分:0)

http://.*mywebsite\.com/(\w+(?:-(?!\d{4,})\w+)*)

Options: ^ and $ match at line breaks

Match the characters “http://” literally «http://»
Match any single character that is not a line break character «.*»
   Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
Match the characters “mywebsite” literally «mywebsite»
Match the character “.” literally «\.»
Match the characters “com/” literally «com/»
Match the regular expression below and capture its match into backreference number 1 «(\w+(?:-(?!\d{4,})\w+)*)»
   Match a single character that is a “word character” (letters, digits, etc.) «\w+»
      Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»
   Match the regular expression below «(?:-(?!\d{4,})\w+)*»
      Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»
      Match the character “-” literally «-»
      Assert that it is impossible to match the regex below starting at this position (negative lookahead) «(?!\d{4,})»
         Match a single digit 0..9 «\d{4,}»
            Between 4 and unlimited times, as many times as possible, giving back as needed (greedy) «{4,}»
      Match a single character that is a “word character” (letters, digits, etc.) «\w+»
         Between one and unlimited times, as many times as possible, giving back as needed (greedy) «+»


Created with RegexBuddy

匹配所有:

http://mywebsite.com/name6-name7-567    name6-name7-567
http://mywebsite.com/name6-name7-567    name6-name7-567
http://www.mywebsite.com/name1-name2-name3-name4-342    name1-name2-name3-name4-342
http://www.mywebsite.com/name5  name5
http://www.mywebsite.com/name6-name7-567    name6-name7-567
http://www.mywebsite.com/name8-name9-name10 name8-name9-name10
http://www.mywebsite.com/name11-name12-name13-name14-name15 name11-name12-name13-name14-name15
http://www.mywebsite.com/name16 name16