Regex help on multiline search & replace
-
Hey guys, I’m pretty new to regex.
I have many text files where I need to do search and replace but am having difficulty when the search pattern is broken up across lines. For example, let’s say we have the following:
Debbie does indeed
Make haste and speed
To Dallas proceedAnd in the above I would want to make a search and replace with words that are separated by line breaks. In the above example I could do, say
^(Debbie does)(.+)(\r\n)(.+)(\r\n)(.+)(Dallas)(.+)$
But this is awkward and I have to know in advance how many line breaks separate the beginning and ending targets. Checking the “matches newline” option finds one giant text block that hungrily marks nearly the whole document. What I want to do here is select the entire line where String A is then continue until finding String B and keep going til the end of that line regardless of how many line breaks separate them.
Thanks for any help!
-
This should help you:
https://notepad-plus-plus.org/community/topic/76/marking-a-large-text
-
Comes pretty close but only selects just after the first target and right before the second. I was looking to select their entire lines. How do I stick it all in a ^ and $?
-
In that case, maybe this one will assist:
https://notepad-plus-plus.org/community/topic/10607/anyone-can-help-with-this-regex/4
There should be sufficient explanation with these links to allow you to adapt them to get your desired solution.
-
Brilliant! Thank you so much Scott! :-)
-
True credit goes to guy038, but I’m glad I could assist.