danski88
danski88

Reputation: 85

Regex - Find matching words that don't begin with a specific prefix in IntelliJ IDEA'a Find in path

I'd like to find any occurrence of specific word which is not preceded by other specific word using IntelliJ IDEA's Find in path (ctrl+shift+f). For example I'd like to find "end" but not "front-end".

There is similar question: Regex - Find all matching words that that don't begin with a specific prefix but solutions from there doesn't work in IntelliJ IDEA.

Do you know any way how to do it in IntelliJ IDEA?

Upvotes: 1

Views: 850

Answers (1)

Wiktor Stribiżew
Wiktor Stribiżew

Reputation: 626689

The problem here is with word delimiting approach. Usually, words consist of letters, digits or _. In your example, - is not a word char.

Since your words are whitespace separated you may use

(?<!\S)(?!front)\S*end(?!\S)

See the regex demo.

Details

  • (?<!\S) - a whitespace or start of string should appear immediately to the left of the current location
  • (?!front) - no front can appear immediately to the right of the current location
  • \S* - 0 or more chars other than whitespace
  • end - end substring
  • (?!\S) - a whitespace or end of string should appear immediately to the right of the current location.

Upvotes: 1

Related Questions