Regex find word in the string

Use this one:

^(.*?(\bpass\b)[^$]*)$
  1. First capture for the entire line.
  2. Second capture for the expected word.

Check the demo.

More explanation:

          ┌ first capture
          |
 ⧽------------------⧼
^(.*?(\bpass\b)[^$]*)$
  ⧽-⧼          ⧽---⧼
   | ⧽--------⧼  |
   |     |       └ all characters who are not the end of the string
   |     |
   |     └ second capture
   |
   └ optional begin characters

Leave a Comment