Using regex to replace a string that is not the replace string

58 views Asked by At

I would like to replace all string that do not equal this: readWriteDataGroup="Everyone" on a file I have open in Notepadd++. One of the strings that it will need to replace has this string: readWriteDataGroup="E_MOD_WSP_64"

So I have been doing this manually but there is over 1000000 lines which is not feasible to be done manually.

How can I do this via regex?

1

There are 1 answers

0
Jerry Jeremiah On

If you search for (readWriteDataGroup=")(?!Everyone")[^"]*(") and replace it with $1X$2 then all the lines that do not contain Everyone in the quotation marks will be replaced with an X.

How that works:

In the search string

  • (readWriteDataGroup=") will match readWriteDataGroup=" and save it as $1
  • (?!Everyone")[^"]* will match any string that isn't Everyone
  • (") will match a trailing " and save it as $2

In the replacement:

  • $1 is the first capture group (readWriteDataGroup=")
  • X is the replacement text
  • $2 is the second capture group (")

You can try it here: https://regex101.com/r/Bum3HU/2

In Notepad++, make sure you select the "Regular Expression" button on the Replace dialog.