regex: find two different strings on two consecutive lines
-
hello. I have this kind of strings, on two consecutive lines. Before and after string, on every line, should be empty:
<p> </p> <p class="text_obisnuit">
So, I need to find all those 2 consecutive lines, and replace it with:
<br><br> <p class="text_obisnuit">
it would have been a simple search and replace if those strings had been positions in the same place, but may be disturbed by spaces before and after. This is why I need a regex.
My solution, is not too good :(
SEARCH:
\S\s(?s)(<p> </p>)\S\s|\n\r|\S\s(?s)(<p class="text_obisnuit">)\S\s
REPLACE BY:<br><br>\n\2
-
so am I correct to assume that you want to change the tags AND
delete the spaces as well?
If so, what about this(\h*<p> </p>)\h*\R\h*(<p class="text_obisnuit">)
? -
yes, Eko, your regex is great !! I write it here again with the replace:
SEARCH:
(\h*<p> </p>)\h*\R\h*(<p class="text_obisnuit">)
REPLACE BY:<br><br>\n\2
Thank you very much
-
Hello, @vasile-caraus, @eko-palypse and All,
Here is, below, a similar regex S/R, with a look-ahead structure, which, also, preserves the indentation of the two lines, involved !
So assuming the sample text, below :
<p> </p> <p class="text_obisnuit"> <p> </p> <p class="text_OTHER_1"> <p> </p> <p class="text_obisnuit"> <p> </p> <p class="text_OTHER_2"> <p> </p> <p class="text_obisnuit">
If we use :
SEARCH
(\h*)<p> </p>(?=\h*\R\h*<p class="text_obisnuit">)
REPLACE
\1<br><br>
the above text becomes :
<br><br> <p class="text_obisnuit"> <p> </p> <p class="text_OTHER_1"> <br><br> <p class="text_obisnuit"> <p> </p> <p class="text_OTHER_2"> <br><br> <p class="text_obisnuit">
With the previous regex S/R, we would have obtained :
<br><br> <p class="text_obisnuit"> <p> </p> <p class="text_OTHER_1"> <br><br> <p class="text_obisnuit"> <p> </p> <p class="text_OTHER_2"> <br><br> <p class="text_obisnuit">
Note, also, that this new regex S/R works, whatever the line endings (
\r\n
for me and\n
for you )Best regards,
guy038