Regex - Find all matching words that that don't begin with a specific prefix

前端 未结 4 1000
误落风尘
误落风尘 2020-12-03 08:14

How would I construct a regular expression to find all words that end in a string but don\'t begin with a string?

e.g. Find all words that end in \'friend\' that don

4条回答
  •  [愿得一人]
    2020-12-03 08:33

    I changed Rob Raisch's answer to a regexp that finds words Containing a specific substring, but not also containing a different specific substring

    \b(?![\w_]*Unwanted[\w_]*)[\w_]*Desired[\w_]*\b
    

    So for example \b(?![\w_]*mon[\w_]*)[\w_]*day[\w_]*\b will find every word with "day" (eg day , tuesday , daywalker ) in it, except if it also contains "mon" (eg monday)

    Maybe useful for someone.

提交回复
热议问题