Replace only specific word within quotes in Notepad++
-
hello everyone, I have the following lines and I would like to just target the “,” that are inside the quotes (ie “,”) and replace it with “;”. Is there a way to do that in Notepad++? Thanks.
test,N,1,“abc,test”,def,3,test,2
test3,N,2,“abc”,“def, ghi”,1656,test,
etc…the result should be:
test,N,1,“abc;test”,def,3,test,2
test3,N,2,“abc”,“def; ghi”,1656,test, -
@Phat-Huynh said in Replace only specific word within quotes in Notepad++:
I would like to just target the “,” that are inside the quotes (ie “,”) and replace it with “;”.
Seems fairly simple. However since you have quotes in your example and did not insert them inside a black box potentially what is shown here may not be the same as you have.
Using the Replace function we have
Find What:(,“[^,”]*),([^”]*)
Replace With:\1;\2
So in the Find What field I copied what your posts shows for the quotes. Check the quotes against your data and if different replace them with what you actually have in the data. A quick test in the Replace function using JUST the Find button will immediately tell you if it does not work, hence the quotes will be the issue.
In any future questions, when inserting examples, once inserted, select them and click on the
</>
button above the post window, this surrounds the examples in a black box.Terry
-
@Terry-R said in Replace only specific word within quotes in Notepad++:
Using the Replace function we have
Find What:(,“[^,”]),([^”])
Replace With:\1;\2Forgot to say that as this is a regular expression the search mode must be “regular expression”.
Terry
-
@Terry-R Thanks Terry. I did what you suggested and just got "Can’t find the text (,“[^,”]),([^”])
screenshot below:
-
Hi @Phat-Huynh
As @Terry-R told you, a missmatching quote style will make the regex fail.
So replace the curly quotes with straight quotes, as follows
Find What:(,"[^,"]*),([^"]*) Replace With:\1;\2
Rest assured, it worked here.
Have fun!
-
@astrosofista @Terry-R Perfect, thank you so much, it worked! Cheers.