1

I have the following regex:

\w*(\.([a-zA-Z0-9]+[-_]+)?careerfy([-_]+[a-zA-Z0-9]+)?)\w*

The above should match the css classes which include the word careerfy and it's variants:

  1. Match .crfy-careerfy
  2. Match .careerfy
  3. Match .careerfy-post
  4. Match .crfy-careerfyds-add-space

The match 4 is not expected and not required!

See https://regex101.com/r/ncd4V9/3

WP-Silver
  • 170
  • 7

1 Answers1

1

You need a custom word boundary after the careerfy word:

\w*(\.([a-zA-Z0-9]+[-_]+)?careerfy(?![^\W_])([-_]+[a-zA-Z0-9]+)?)\w*
                                  ^^^^^^^^^^ 

See the regex demo.

The (?![^\W_]) will not let match careerfy if it is followed with a letter or digit.

See the regex graph: enter image description here

enter image description here

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563