开发者

regex query to get all matches for a path

开发者 https://www.devze.com 2022-12-27 04:28 出处:网络
Yep - another noob regex query, which I can\'t seem to get. I\'m trying to get all matches for the string foo.mydomain.com/ or foo.mydomain.com:1234/ or foo.mydomain.com:<random port>/ but any

Yep - another noob regex query, which I can't seem to get.

I'm trying to get all matches for the string foo.mydomain.com/ or foo.mydomain.com:1234/ or foo.mydomain.com:<random port>/ but any other paths do not match, ie. foo.mydomain.com/bar or foo.mydomain.com/bar/pewpew

I tried to use: foo.mydomain.com(.*)/$ (which starts with anything, then foo.mydomain.com, then any thing after that until a slash, then end. (This search query is anchored to the end of the line.)

But that doesn't work. It doesn't match when I pass in foo.mydomain.com:123开发者_运维百科4 but it correct says foo.mydomain.com/bar/pewpew is not a match (as expected).


Try:

^foo\.mydomain\.com(?::\d+)?/?$
  • ^ : Start anchor
  • \. : . is a meta char..to match a literal . you need to escape it with \
  • (?:) : grouping
  • \d : A single digit
  • \d+ : one or more digits
  • ? : makes the previous pattern optional
  • $ : End anchor


foo\.mydomain\.com(:\d{1,5})?/\s*$

Try this one.

0

精彩评论

暂无评论...
验证码 换一张
取 消