Add double quote on different words in notepad++
-
hello,
I have a file that I need to replace all the text in a line with “” (double quote),
for example :
USR.MDM-JKT-SIS-01 USR.MDM-JKT-SIS-LONG USR.MDM-JKT-SIS-AA USR.MDM-JKT-SIS-TMP
I don’t care for the text of USR.MDM, I just need add " " (double quote) on the entire of text , for i.e.after replace it will have :
"USR.MDM-JKT-SIS-01" "USR.MDM-JKT-SIS-LONG" "USR.MDM-JKT-SIS-AA" "USR.MDM-JKT-SIS-TMP"
I need to find the regex, because it was not only a several line, but it almost 10k line, and it awful to change one by one using notepad++
thank you
-
you need to use regular expressions in search mode . search :
(.*\..*-.*-.*-.*)\R
replace:"$1"
. please use the mark function first to check if all the search matching is right , use with care , may contain error of mine . -
@Aswin-Hadinata said in Add double quote on different words in notepad++:
I just need add " " (double quote) on the entire of text
If the above quoted text states that EVERY line needs the
"
added to each end of the line the following seems to fit.
Using Replace function:
Find What:^|$
Replace With:"
search mode must be regular expression. Click on Replace All to do it all in one step.Seasons Greetings to one and all
Let’s hope for a brighter 2021
Terry -
So that you know, @carypt’s solution only works on lines that follow the same pattern as the you originally posted. Sometimes when helping, we derive patterns (intentionally or not, implicitly or explicitly) from the example data that the OP posts – for example, maybe you really meant “every line that follows the pattern in the example data” – but given the “every”, that’s more restricted of a regex than I would have likely gone with, myself. As always when trying regular expressions suggested in a forum, make sure you have your data saved, and that you can undo any change that is made.
The better you give your data – showing exceptions, odditities, or lines in your data that shouldn’t transform, along with lines that should – the better your replies will be.
@Terry-R ,
If you have an empty line anywhere in the file, your replacement will have a lone quotemark, rather than a pair of quote marks, on those blank lines:
If there are no empty lines in the OP’s actual data, then there’s no problem. But if there is, it won’t be as expected.
Alternates:
-
use FIND:
(?-s)^.+$
=> REPLACE:"$0"
, my example will become*:
-
use FIND:
(?-s)^.*$
=> REPLACE:"$0"
, my example will become*:
So it depends on whether “every line” means “every nonempty line” or “every line, even if it’s empty” (or “every line that looks similar to the pattern inferred from the example data”) which regex will be best for you.
—
Footnote *: The regular expressions I show require☑ Regular Expression
to be enabled. The(?-s)
at the beginning of each FIND expression were there to make the expression have.
not match newlines, no matter what the setting of the☐ . matches newline
option.----
Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as literal text using the
</>
toolbar button or manual Markdown syntax. To makeregex in red
(and so they keep their special characters like *), use backticks, like`^.*?blah.*?\z`
. Screenshots can be pasted from the clipboard to your post usingCtrl+V
to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get. Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries. -
-
search :
(.*\..*-.*-.*-.*)\R
replace: “$1”Actually, if you include
\R
at the end of the match, then when you do the replacement, you have stripped out the newline and all the lines would merge together as
If you changed that to
(.*\..*-.*-.*-.*)$
, then it won’t merge the lines.@Aswin-Hadinata , I still wouldn’t recommend this version unless all the lines that need to be quoted match the pattern of TEXT DOT TEXT HYPHEN TEXT HYPHEN TEXT HYPHEN TEXT. But if you do choose to go down this route, the
\R
will trip you up. -
@PeterJones yes , thank you , the replace should have been “$1”\r\n at least , or i should have taken the \R into brackets in the search string , and added it into “$1”$2 . but i missed the concept that the whole search string gets replaced , if i dont instruct a rebuilding in replace . oops , my mind wasnt working .
i am sorry @Aswin-Hadinata