Reputation: 1199
I am fairly new to regular expression therefore this may be the simplest question you've seen on StackOverflow :-)
I have a large JSON file with text like this:
{..., "text": "BLAH BLAH", ...}
The text may contain any of the special characters and also characters like \"
, which I understand can be seen as escape character in regular expression. I am trying to find and replace a single character colon :
with tilde ~
within the portion followed by "text"
preferably in Notepad++. Any help will be greatly appreciated.
Upvotes: 1
Views: 2837
Reputation: 89649
You can do this:
find: ("(?:[^"]+|(?<=\\)")*")\s*:
replace: $1~
The idea is to capture the content inside double quotes, to put it in the replacement.
I use a lookbehind to allow escaped double quotes inside double quotes.
Upvotes: 0
Reputation: 15010
This regex will find all the :
in the value for fields named text
and replace the character with a ~
. Note there were issues using regular expressions with Notepad++ v5. My demo here was tested in Notepad++ v6.3.3
Regex: ("text":\s"[^"]*?):
Replace with: $1~
Input string: {"not text": "12:34", "text": "BLAH:BLAH", "Never get a": ":oskupee"}
Upvotes: 1
Reputation: 1199
Here is what I did (thanks for all the help @Mike, but I had to make many edits. That's why I am answering my own question so other users can get the complete answer)
\"text\": \".*? : .*?\",
in Notepad++\1~\2
to replace all :
with ~
Upvotes: 0