Community
    • Login

    How to stop searching or replacing after a string?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    regex
    24 Posts 5 Posters 2.3k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • dr ramaanandD
      dr ramaanand @guy038
      last edited by dr ramaanand

      @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

      1 Reply Last reply Reply Quote 0
      • dr ramaanandD
        dr ramaanand @PeterJones
        last edited by dr ramaanand

        @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!

        dr ramaanandD 1 Reply Last reply Reply Quote 0
        • dr ramaanandD
          dr ramaanand @dr ramaanand
          last edited by

          @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.

          PeterJonesP 1 Reply Last reply Reply Quote 0
          • PeterJonesP
            PeterJones @dr ramaanand
            last edited by PeterJones

            @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.

            dr ramaanandD 1 Reply Last reply Reply Quote 0
            • dr ramaanandD
              dr ramaanand @PeterJones
              last edited by dr ramaanand

              @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!

              dr ramaanandD PeterJonesP 3 Replies Last reply Reply Quote 0
              • dr ramaanandD
                dr ramaanand @dr ramaanand
                last edited by dr ramaanand

                This post is deleted!
                1 Reply Last reply Reply Quote 0
                • PeterJonesP
                  PeterJones @dr ramaanand
                  last edited by PeterJones

                  @dr-ramaanand ,

                  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.

                  dr ramaanandD 1 Reply Last reply Reply Quote 3
                  • dr ramaanandD
                    dr ramaanand @PeterJones
                    last edited by dr ramaanand

                    @PeterJones I am sorry if it offended you. I didn’t mean to.

                    1 Reply Last reply Reply Quote 0
                    • dr ramaanandD
                      dr ramaanand @dr ramaanand
                      last edited by dr ramaanand

                      @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> !

                      mkupperM 1 Reply Last reply Reply Quote 0
                      • mkupperM
                        mkupper @dr ramaanand
                        last edited by

                        @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.

                        1 Reply Last reply Reply Quote 2
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors