Search for a text and copy the previous lines of codes
-
@PeterJones Just for your information, I had typed, “
(?<=def)
” above, not, “(?<!def)
”. -
@Scott-Nielson said in Search for a text and copy the previous lines of codes:
Just for your information, I had typed, “(?<=def)” above, not, “(?<!def)”.
Specifically, you typed
(?<!abc)(?<!xyz)(?<!xxx)(?<=def)
. My previous post stands correctly as a comment on that regular expression as you typed it. It was a group of four sub-expressions: three negative lookbehinds and one positive lookbehind. My point #1 referred to the first three negative lookbehinds. My point#2 referred to the final positive lookbehind. I stand by my previous assessment of your regular expression. -
@PeterJones got it, thanks.
So for the stringBible. <a href=www.jw.org>Jehovah's witnesses</a> Atheists abc xyz xxx </span> </p>
if I had to find just, “
</span>
” and
“</p>
” when the “</p>
” is on the next line, this RegEx should be fine right:(?<!/a)(?<!abc)(?<!xyz)(?<!xxx)(?<=/span)>\s*</p>
? -
this RegEx should be fine right
I do not believe you have understood what I have tried to explain previously. As I have said to you multiple times, if it works for you, great! This forum doesn’t exist to be a regex “do-your-homework-for you” site, nor a “tell-me-if-my-regex-is-right” site, nor a regex tutorial site, or a “regex-for-dummies” site, nor a “let’s-talk-about-regex-and-nothing-else” site.
Regular expressions are just a small part of what Notepad++ can do, and once we’ve helped a given user a couple times with regular expressions (and trust me, you’ve gone beyond “a couple” at this point), and pointed the same user multiple times to all the resources that on regular expressions – including the Notepad++ Online User Manual section on search/replace for the canonical reference to Notepad++ regular expressions, and the regular expression FAQ with links to lots of online regex-learning resources, both linked above – then we expect that user to make more use of those documents and links, and take the onus of learning regular expressions upon themselves, rather than expecting us to generate or proofread their every regular expression.
Some personal advice: the only way you are going to learn more about regular expressions at this point is to experiment with them yourself, and read the resources, and try it on your own; us giving you a “seal of approval” won’t help, and us spoon-feeding you a regex that works with the small example data you share won’t help you learn how to do it on your own.
Good luck.
-
Hello, @scott-nielson, @peterjones, @alan-kilborn, @terry-r and All,
@scott-nielson, when you said in an older post :
what RegEx can help skip searching for abc in abcdef, xyz in xyzdef and xxx in xxxdef (all at once, with just one RegEx)?
The @peterjones’s answers are just the right ones :
-
(?:abc|xyz|x+)\h*\Kdef
with the\K
construction -
(?<=(?:abc|xyz|xxx)\h*)def
with a positive look-behind
Back to your last post, IF you had tried the regex
(?<!/a)(?<!abc)(?<!xyz)(?<!xxx)(?<=/span)>\s*</p>
, you could have seen that this regex, as well as all the following ones :(?<!abc)(?<!xyz)(?<!xxx)(?<=/span)>\s*</p>
(?<!xyz)(?<!xxx)(?<=/span)>\s*</p>
(?<!xxx)(?<=/span)>\s*</p>
(?<=/span)>\s*</p>
just match a
>
, followed by any number of vertical or horizontal blank characters, even none and, next, the</p>
stringOf course, if you’re really looking for this, the simple regex
>\s*</p>
seems enough ;-))Or, as you said :
If I had to find just, “</span>” and “</p>” when the “</p>” is on the next line …
may be, this other one
</span>\s*</p>
Now, if you looking for any block
</span> ••••• </p>
, after a line<a href ••••• > ••••• </a>
which do not contain, in the middle, any textabc
,xyz
andxxx
, with this exact case, the following regex should work :SEARCH / MARK
(?s-i)</a>((?<!abc)(?<!xyz)(?<!xxx).)*?\K</span>\s*</p>
Test it against this example :
Bible. <a href=www.jw.org>Jehovah's witnesses</a> Atheists abc </span> </p> Bible. <a href=www.jw.org>Jehovah's witnesses</a> xyz Atheists other text added </span> </p> Bible. <a href=www.jw.org>Jehovah's witnesses</a> Atheists Line 1 xxx Line 2 Line 3 </span> </p> Bible. <a href=www.jw.org>Jehovah's witnesses</a> Atheists Line 1 Line 2 Line 3 </span> </p> Bible. <a href=www.jw.org>Jehovah's witnesses</a> Atheists First sentence Second sentence Third sentence </span></p>
As you can verify, this regex just matches the
4th
and5th
blocks, which do not contain any textabc
,xyz
andxxx
, between</a>
and</span>
Note that I use the
\K
syntax, because, due to non-fixed length generated by the*?
non-greedy quantifier, a look-behind syntax cannot be used, in this situation !Best Regards,
guy038
-
-
@guy038 thanks a lot. I don’t know what I would have done without your help!
-
@guy038 Suppose if I don’t have a link, that is
</a>
and I am not sure what to put there (because it varies), will this RegEx work if I am using the same search strings that you typed above:(?s-i)((?<!abc)(?<!xyz)(?<!xxx).)*?\K</span>\s*</p>
?