How do I find some text but skip some other slightly different text?
-
@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! -
@PeterJones When this is found:
-</span>)
, with no space in between, no replacement should happen. -
@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. -
This post is deleted! -
@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. -
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>)
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 spanFIND =
(?s)(?<=mso-ansi-language:EN-US'>)-((?:(?!\h*</span>).)+?) *(?=</span>)
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.
-
@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.
-
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
-
@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! -
@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!