Community
    • Login

    How do I find some text but skip some other slightly different text?

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    22 Posts 3 Posters 3.5k Views 2 Watching
    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.
    • Scott NielsonS Offline
      Scott Nielson @PeterJones
      last edited by Scott Nielson

      @PeterJones Like you said, I used the RegEx, (?s)(?<=mso-ansi-language:EN-US'>)-(.+?) *(?=</span>) and that skips finding the immediate next </span> and finds the next one but I want the RegEx to skip replacing a “hyphen” or “dash” if the </span> is immediately after the “hyphen” or “dash” (without any space in between) which means the (.+?) is not needed here. There’s a difference between “finding” and “replacing”. Please help!

      PeterJonesP 2 Replies Last reply Reply Quote 0
      • Scott NielsonS Offline
        Scott Nielson @PeterJones
        last edited by

        @PeterJones When this is found: -</span>), with no space in between, no replacement should happen.

        1 Reply Last reply Reply Quote 0
        • PeterJonesP Offline
          PeterJones @Scott Nielson
          last edited by

          @Scott-Nielson said in How do I find some text but skip some other slightly different text?:

          (.+?)

          change (.+?) => ((?:(?!</span>).)+?) – this gets complicated, and you will need to study the manual and play with it to fully understand. But basically, the (?!</span>) is a negative lookahead saying that the next characters cannot be </span>, but doesn’t grab any; then the . following grabs the first character that doesn’t start </span>. Then the ()+ says continuing doing this (grab one character as long as it isn’t the start if </span>) as long as I can.

          Scott NielsonS 1 Reply Last reply Reply Quote 0
          • PeterJonesP Offline
            PeterJones @Scott Nielson
            last edited by

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • Scott NielsonS Offline
              Scott Nielson @PeterJones
              last edited by Scott Nielson

              @PeterJones Like you said, I used the RegEx, (?s)(?<=mso-ansi-language:EN-US'>)-((?:(?!</span>).)+?) and that finds the hyphen/dash and the immediate next character (which is not what I want). I think, we need a RegEx with a (SKIP) in it.

              PeterJonesP 1 Reply Last reply Reply Quote 0
              • PeterJonesP Offline
                PeterJones @Scott Nielson
                last edited by PeterJones

                @Scott-Nielson

                You got rid of parts of your previous regex which I didn’t say to remove, which my answer assumed would still be used. If you really need SKIP, you’ll have to wait for someone else, because I have never understood it. But I personally don’t think you need it.

                DATA =

                mso-ansi-language:EN-US'>-blah blah blah</span> <!-- yes this one -->
                mso-ansi-language:EN-US'>-</span> <!-- not this one -->
                mso-ansi-language:EN-US'>- </span> <!-- unsure about this one -->
                

                FIND = (?s)(?<=mso-ansi-language:EN-US'>)-((?:(?!</span>).)+?) *(?=</span>)

                78445101-1dfc-4128-9bac-eb8e0f32b1be-image.png

                That seems to match what you said, where you want it to not match if it’s -</span> with no space between; you weren’t clear whether it should match with a space in between; the one I had intended you to use (which I just showed) assumed one with hyphen space span should match, like in my screenshot. If not, then tweak it again to not allow spaces before the span

                FIND = (?s)(?<=mso-ansi-language:EN-US'>)-((?:(?!\h*</span>).)+?) *(?=</span>)

                b7ec4a8a-e1f1-404f-8a55-fe2c049f8b3c-image.png

                At this point though, if you want more help, you will have to do a better job showing your problem – what you have, what you get, and what you actually want, without irrelevant bits – and do a better job of doing what we suggest; you will also have to wait for someone who knows FAIL, and has the ability to answer in ways that you will understand – so you’ll have to have patience while waiting for someone else to show up.

                Scott NielsonS 1 Reply Last reply Reply Quote 0
                • Scott NielsonS Offline
                  Scott Nielson @PeterJones
                  last edited by

                  @PeterJones The RegEx you gave me worked like a charm and I’m happy with it but if someone does post about how to use SKIP and FAIL, it’d be nice.

                  Alan KilbornA 1 Reply Last reply Reply Quote 0
                  • Alan KilbornA Offline
                    Alan Kilborn @Scott Nielson
                    last edited by

                    @Scott-Nielson

                    For what it’s worth, here are some links I’ve collected which discuss (*SKIP), (*FAIL), or both:

                    • https://community.notepad-plus-plus.org/post/55467
                    • https://community.notepad-plus-plus.org/post/60429
                    • https://community.notepad-plus-plus.org/topic/20432
                    • https://community.notepad-plus-plus.org/post/64421
                    • https://community.notepad-plus-plus.org/post/60332
                    • https://community.notepad-plus-plus.org/post/60220
                    Scott NielsonS 2 Replies Last reply Reply Quote 0
                    • Scott NielsonS Offline
                      Scott Nielson @Alan Kilborn
                      last edited by Scott Nielson

                      @Alan-Kilborn This RegEx, -</span>(*SKIP)(*F)|(\a)|(?s)(?<=mso-ansi-language:EN-US'>)-(.*?) *(?=</span>) skipped what I wanted it to and replaced only what I wanted it to. Thanks a million!

                      1 Reply Last reply Reply Quote 0
                      • Scott NielsonS Offline
                        Scott Nielson @Alan Kilborn
                        last edited by Scott Nielson

                        @Alan-Kilborn Sorry, that should be, -</span>(*SKIP)(*F)|(?s)(?<=mso-ansi-language:EN-US'>)-(.*?) *(?=</span>) - I forgot to copy the last RegEx and your system doesn’t let me edit what I post after 3 minutes!

                        1 Reply Last reply Reply Quote 0

                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                        With your input, this post could be even better 💗

                        Register Login
                        • First post
                          Last post
                        The Community of users of the Notepad++ text editor.
                        Powered by NodeBB | Contributors