0

I am matching a string in form: Page 1 of X where X is a digit with the simple Page 1 of \d+

How can I match the same string as above except ensuring Y is a number but not a 1 in the expression Page Y of X.

Page 1 of 41   **no match**
Page a of 41   **no match**
Page 12 of 111 **match**

The solution I am trying seems not to work

Page ^(?!(?:1)$)\d+ of \d+
notverygood
  • 197
  • 8
  • Use a negative lookahead to "exclude" specific values that a more generic pattern can match. – Wiktor Stribiżew Aug 26 '20 at 12:46
  • Trying a lookhead with `Page ^(?!(?:1)$)\d+ of \d+` is not working – notverygood Aug 26 '20 at 12:48
  • I think it should be `Page (?!1\b)\d+ of \d+` Or match `Page (?:[02-9]|[1-9]\d+) of \d+` – The fourth bird Aug 26 '20 at 12:49
  • Sure because `$` is end of string. Is there end of string after `1` at that location? `\b` word boundary is not necessary, a space can also be used, `(?!1 )\d+`, because after the number, there must be a space. A non-capturing group around a hardcoded pattern is meaningless, `(?:1)` = `1`. – Wiktor Stribiżew Aug 26 '20 at 12:49

0 Answers0