1

I am having trouble matching a pattern of this format: p#.g.com where # is not a 1 or a 2. For instance if the pattern is p1.g.com, I don't need to match. If it it p2.g.com, I don't need to match.

But if it is any other number, such as p3.g.com or p29.g.com, then I need to match.

My current pattern is r"(?P<url>p([^1,2])\.g\.com)", but this fails if the pattern is p##.g.com, basically any two digit number it fails on. There is no upper limit on the #, so it could be a 3 or 999 or anything in between.

I also tried r"(?P<url>p([^1,2])\d+\.g\.com)" but that does not match any number beginning with a 1 or a 2. For instance 11 or 23 are not matched, which I do want matched.

2
  • try, p\d+\.g\.com ? Commented Oct 19, 2021 at 4:33
  • That's going to match p1.g.com and p2.g.com, which I don't want. Commented Oct 19, 2021 at 4:37

1 Answer 1

3

Try this regex:

p(?:[03-9]|\d{2,})\.g\.com

Demo

Explanation:

  • Matches character p
  • Start of non-capturing group
    • Match one of:
      • The digits 0 or 3-9
      • Any double digit number like 10 or higher
  • Matches character .g.com
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.