Regex replacement of text within regex find
-
I want to find text using regex and then replace some of the characters within the found strings…
e.g. I have this text:"dataLabels": { "show": true, "name": { "show": true, "fontSize": "16px", "fontFamily": "undefined", "fontWeight": 600, "color": "undefined", "offsetY": -10 }, "value": { "show": true, "fontSize": "14px", "fontFamily": "undefined", "fontWeight": 400, "color": "undefined", "offsetY": 16, "formatter": "function (val) { return val + " % " }" }, "total": { "show": false, "label": "Total",
and this regex expression:
"formatter": function([\s\S]+?)}
This will find this:
"formatter": "function (val) { return val + " % " }"
I want to replace the
" % "
with' % '
There could be any number of these formatter finds I need to replace.Not sure if it’s possible to do with npp?
-
Reading between the lines, I would infer that you want to replace
" % "
but only when it occurs on the same line as"formatter": "function
between exactly that and}"
+ line-ending. Is that correct? -
Hello @nick-minchin, @alan-kilborn and All,
Here is the road map for this S/R :
-
Open your file in Notepad++
-
Go to the very beginning of this file (
Ctrl + Home
) -
Open the Replace dialog (
Ctrl + H
) -
SEARCH
(?x-si) ( ^ \h* "formatter":\x20+"function | (?!\A) \G ) .*? \K " (?!$)
-
REPLACE
'
-
Un-tick all options
-
Select the
Regular expression
search mode -
Click on the
Replace All
button ( Do not use theReplace
button !)
Voila !
This S/R will replace any non-trailing double quote
"
, only after the string"formatter": "function
, with a simple quote'
, in all the lines of your fileBest Regards
guy038
-