Search code examples
javascriptregexintellij-idea

Regular expression to find string which is not part of bigger subscript


I have a very big file with text and want to find:

  1. all occurrences of string selectedRow which are not:
  2. part of selectedRowIds
  3. are proceeded by props.

I am interested in line numbers where all of these conditions are met.

Is is possible to achieve with RegExp?

So e.g. for test data:

this.state.selectedRow
this.props.selectedRow
selectedRowIds

it will match only first line.


Solution

  • You can use look around to exclude matches with particular prefix/postfixes:

    (?<!props\.)selectedRow(?!Ids)