1

I have strings in the form of

[Identifier][Keyword][Number]Text

Where identifier is \w*, Keyword is one of Button, Link, or Text, Number is [0-9]* and text is the literal word Text. I am trying to match strings that don't fit this pattern.

Examples I would like matched:

  • MyIdentifier
  • MyIdentifierText
  • MyIdentifierButton
  • MyIdentifierButton1
  • Button
  • Button1
  • Text

Examples I don't want matched:

  • ButtonText
  • MyIdentifierButtonText
  • Button1Text
  • MyIdentifierButton1Text
  • TextText
  • Text1Text

I have come up with this:

^\w*(?:(?<!Button)|(?<!Link)|(?<!Text))[0-9]*(?<!Text)$

That is correct except it does not match the following:

  • Text
  • MyIdentifierText

I know the issue is with the first lookbehind, but I'm not sure how to fix it. I have read this and it didn't help, but that question also didn't have a wildcard before the lookbehind.

Barmar
  • 741,623
  • 53
  • 500
  • 612

0 Answers0