How to stop searching or replacing after a string?
-
@guy038 there is only one, “
<h2>
” and one, “</h2>
” in the file, so what @PeterJones helped me, “guess”, based on what you typed in an earlier thread seems to be good enough -
@PeterJones using “
(?-si:<h2|(?!\A)\G)(?s-i:(?!<\/h2).)*?\K(?-si:<\/p>\R<p[^<>]*>)
” in the “Find what” field and “</h2>\r\n<h2>
” in the “Replace All” field is working perfectly. Thank you very much. Happy New Year! -
@PeterJones @guy038 I am sorry to say that I tested this on my laptop just now as I was busy with the New Year celebrations and observed that the RegEx which Peter Jones told me to use is also replacing only one
</p>
and one<p.............. >
on the next line instead of replacing all at once. -
@dr-ramaanand said in How to stop searching or replacing after a string?:
@PeterJones @guy038 I am sorry to say that I tested this on my laptop just now as I was busy with the New Year celebrations and observed that the RegEx which Peter Jones told me to use is also replacing only one
</p>
and one<p.............. >
on the next line instead of replacing all at once.I’m sorry to say that my experience is different than yours. Replace All with the regex I suggested works all at once.
-
@PeterJones it looks like you took a long time to reply, so I asked at www.regex101.com and was told to use, “
(?-si:<h2[^<>]*+>|\G)[^<>]*+\K<\/p>\s*+<p[^<>]*+>
” which is replacing all that I want replaced, all at once! -
This post is deleted! -
It was less than an hour. if that’s a “long time” in your mind, then using a free, Community-based service is probably not the right question/answer format for you. I would suggest finding someone to pay to give you instant 24/7/365.2425 support. Because you aren’t going to find anything guaranteed faster in any free online Q&A site.
And as we’ve told you before, regex101 uses a different flavor of regex engine than Notepad++ does, so there is no guarantee that a regex suggested by that site will be compatible with Notepad++. Use at your own risk.
Further, as you have reported multiple times, and as my video showed, the regex shown does work (as you once said, “perfectly”), and you didn’t need my video to know that. If you want to use a different regex, that’s fine, go ahead and use whatever “works” for you. But don’t pretend (and publically state) that it was a defficiency in the regex already given to you or a “slow response” from me or any of the other regulars here who answer questions out of the kindness of our hearts.
-
@PeterJones I am sorry if it offended you. I didn’t mean to.
-
@dr-ramaanand said in How to stop searching or replacing after a string?:
(?-si:<h2[^<>]*+>|\G)[^<>]*+\K<\/p>\s*+<p[^<>]*+>
@guy038 or anybody else, can you please explain what the above RegEx does (since it is working on Notepad++)? It replaces all the
</p>
and the<p............ >
immediately after that, even if it’s on the next line, all at once with</h2>
and<h2>
on the immediate next line, if I put</h2>\r\n<h2>
in the “Replace with” field and hit “Replace All” with the Regular expression mode ticked and the matches newline unticked. The best thing about it is it does not do any replacing after the last</h2>
! -
@dr-ramaanand I think the people on regex101 are using ChatGPT or other artificial intelligence applications to generate regular expressions.
The expressions you get from regex101 are extremely difficult to follow do not come with any explanation of how the logic works or why certain choices were made. It’s likely that the regex101 people also have little to no idea of what the expressions do.
That’s a large part of why using ChatGPT or other artificial intelligence applications is banned on this forum. Ideally, we call can learn from the answers we see posted on this forum.
As I posted earlier, it would be much better for you to so stick with things you know and understand well. It’s ok to push the limits a little at times as you can learn from those. Trying to make sense of what looks like AI generated content is a waste of time.