Replace text inside double quotes
-
friends how can i replace some text inside the quotes
“concerto” “.uk” site:usa
“maestro” + “.mx” + site:usato
“Festival” “.uk” site:usa
“Singer” + “.mx” + site:usa -
With the simple samples you gave, I would just do two searches:
- FIND =
"concerto"
, REPLACE ="Festival"
- FIND =
"maestro"
, REPLACE ="Singer"
But I am sure that’s not sufficient for your real needs. Hopefully, if you want more help than I was able to provide, you will explain in more detail what you want. If you follow the advice below, the help you get will be even better.
----
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. - FIND =
-
@PeterJones
Thanks for your help, i was actually looking for the regex to replace text inside quotes but i can’t do every single word working with huge files -
@Clyde-Parker said in Replace text inside double quotes:
Thanks for your help, i was actually looking for the regex to replace text inside quotes but i can’t do every single word working with huge files
Yeah, you’re still not giving us enough to go on. The regex
".*?"
will match text inside a quote, or^".*?"
will match only text inside a quote that begins a line, or(?<^").*?(?=")
will match the text inside the quotes at the start of a line, without matching the quote marks themselves. But there is no easy way to make a map of word->replacement in the REPLACE portion of the regex.if you’ve got a list of 5-10 words that you HAVE, and the associated words that you WANT to convert them to, then it’s not too difficult to produce a regex that will do it. But if you’ve got hundreds or thousands of words that you want to map from one to another, you won’t be able to do it in a single manual regex.
That said, our resident regex gurus have some tricks up their sleeves. So if you said you were able to put the list of HAVE => WANT words at the end of the file, and weren’t picky about the format for that list, someone might be able to chime in with a way to get that to miraculously transform it.
Personally, while I find such solutions academically interesting the first time I see them, they have their limitations (if the main text file gets too long, the magic regex cannot extend all the way from the real text to the mapping at the bottom).
Really, if I were doing this, once it got to this stage of a huge list of replacement maps, I would just write a command-line script to do it in my favorite programming language; but that’s off-topic here.
But if I were going to solve this “inside” Notepad++, I would pull out a plugin like PythonScript: open the text to be edited in the “main” editor view and a separate file that would have the
HAVE => WANT
pairs in some easy-to-parse format (likeHAVE => WANT
orHAVE,WANT
orHAVE [tab] WANT
) and write some python code which would process the mapping file view line-by-line, then run the search-and-replace on the main editor view, and loop through all the changes you want to make. I’m actually pretty sure someone has shown such code in the forum before – maybe even me. But searching the forum for “PythonScript map” or some such will produce a lot of results that you’d have to wade through to find – and you might have to try variations, because everyone phrases it differently.Again, I highly recommend reading the advice I gave above, and trying to add enough information that someone could meaningfully give a detailed solution, rather than just my high-level “if you’re lucky, it might be doable with fancy regex, but we cannot know until you give us more detail; or it could also be done through scripting, but how exactly that will look might depend on what your data is really like, and what format your list of replacements is in”.