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 1.1k 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.
    • Scott NielsonS
      Scott Nielson @PeterJones
      last edited by

      @PeterJones How do I skip replacing a “hyphen” or “dash” if the </span> is immediately after the “hyphen” or “dash” (for what I’ve posted right at the top)? Please tweak the RegEx so that it skips it. Thanks in advance for your help!

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

        @Scott-Nielson ,

        If you want to require at least one character after the hyphen, then why not make your regex require “1 or more” characters instead of “0 or more” characters after the hyphen: specifically, change (.*?) to (.+?)

        ----

        Please note: This Community Forum is not a data transformation service; you should not expect to be able to always say “I have data like X and want it to look like Y” and have us do all the work for you. If you are new to the Forum, and new to regular expressions, we will often give help on the first one or two data-transformation questions, especially if they are well-asked and you show a willingness to learn; and we will point you to the documentation where you can learn how to do the data transformations for yourself in the future. But if you repeatedly ask us to do your work for you, you will find that the patience of usually-helpful Community members wears thin. The best way to learn regular expressions is by experimenting with them yourself, and getting a feel for how they work; having us spoon-feed you the answers without you putting in the effort doesn’t help you in the long term and is uninteresting and annoying for us.

        Scott NielsonS 2 Replies Last reply Reply Quote 0
        • Scott NielsonS
          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
            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
              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
                PeterJones @Scott Nielson
                last edited by

                This post is deleted!
                1 Reply Last reply Reply Quote 0
                • Scott NielsonS
                  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
                    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
                      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
                        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
                          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
                            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
                            • First post
                              Last post
                            The Community of users of the Notepad++ text editor.
                            Powered by NodeBB | Contributors