user3153443
user3153443

Reputation: 563

Notepad++ Regex - Finding and replacing multiple different criteria simultaneously

I've just started to get to grips with regex in notepad++ and I've tasked myself with formatting a chunk of JSON data into something human readable, as well as something that can be read into an algorithm a colleague of mine wrote. I've found a few regex expressions that do this perfectly, but in order to get to my desired result, I have to do it in four separate Find/Replace steps. Is there some sort of way I can create one single find/replace expression that handles all of the above tasks for me?

Currently I have Notepad++ doing the following:

  1. Deleting all quotation marks by finding " and replacing it with nothing
  2. Deleting all commas by finding , and replacing it with nothing
  3. Changing all underscored numbers that are followed by a colon with the number 0 (the reason behind this is particular to the project) by finding _[0-9]*: and replacing with _0 and finally, putting all of a particular expression onto it's own line by finding the start of the particular string I'm after and adding \n.

I know that's convoluted, but fortunately it does the job. Is there any way of consolidating all that into a single command, or does that all have to be done step by step?

Thanks guys :)

Upvotes: 0

Views: 720

Answers (1)

JonM
JonM

Reputation: 1374

Notepad ++ allows you to consolidate individual search and replaces as a macro which you can also save.

  1. Hit the record button in the toolbar (or Macro>Start Recording)
  2. perform these regex replacements in the required order.
  3. hit stop button in toolbar (or Macro>Stop Recording)
  4. Hit the play button to perform all the required replacement operations again.
  5. Save the macro by going into the Macro option in the window menu and 'save current recorded macro'

As for the first to replacements you could use the following expression: (?:"|,)

Upvotes: 1

Related Questions