I was trying to use Notepad++ to skip two strings before a particular string using the regular expression negative lookbehind for two strings for this block but failed to:-
<html>
<p style="font-family: "verdana"; font-size: 18px; color: black; line-height: 18px; text-align: justify; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: cyan;"><span style="font-size: 13.5pt; font-family: "Verdana","sans-serif";"><code style="background-color: transparent;"><b>some text here</b></code></span></p>
<span><span style="font-size: 13.5pt; font-family: "Verdana","sans-serif"; background-color: cyan;"><code style="background-color: transparent;"><b>some text here</b></code></span>
<code style="background-color: transparent;">
<p style="font-family: "verdana"; font-size: 18px; color: cyan; line-height: 18px; text-align: justify; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: cyan;"><span style="color: black; font-size: 13.5pt; font-family: "Verdana","sans-serif";"><code style="background-color: transparent;"><b>some text here</b></code></span></p>
<span><span style="font-size: 13.5pt; font-family: "Verdana","sans-serif"; background-color: cyan;"><code style="background-color: transparent;"><b>some text here</b></code></span>
<p style="font-family: "verdana"; font-size: 18px; color: cyan; line-height: 18px; text-align: justify; font-style: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; background-color: navy;"><span style="font-size: 13.5pt; font-family: "Verdana","sans-serif";"><code style="background-color: transparent;"><b>some text here</b></code></span></p>
</html>
Then, the Regular expression ((?:<p[^>]*?color: black.*?>[\S\s\n]*?<\/p>\s*<span[^>]*>)|(?:<span[^>]*?color: black.*?>[\S\s\n]*?<code))(*SKIP)(*F)|<code\s*style="background-color:\s*transparent;">
helped find what I wanted (after skipping some strings), in the opened, current file - that is, it helped skip finding the <code\s*style="background-color:\s*transparent;"[^>]*>
if it was preceded by <p.......color: black...>(any white spaces, including if they were on the next line)<span.......>
, or <span.......color: black...>
and found other strings of <code\s*style="background-color:\s*transparent;"[^>]*>
- but not in all the files of a folder (when I selected, "Find in files" and clicked on, "Replace in files"), probably because it is getting into a continuous loop. How to avoid it from getting into a loop?
I get an, "Invalid Regular expression" error if I try to find this or replace this in multiple files of a folder; then on clicking the [...]
icon next to where it shows that, "Invalid Regular expression", error, I am getting this message: "The complexity of matching the regular expression exceeded predefined bounds. Try refactoring the regular expression to make each choice made by the state machine unambiguous. This exception is thrown to prevent eternal matches that take an indefinite period time to locate."
This regular expression helped find <code\s*style="background-color:\s*transparent;"[^>]*>
if it was not preceded by 4 strings, that is <p.......color: black...>(any white spaces, including if they were on the next line)<span.......>
, <li style.......color: black...>(any white spaces, including if they were on the next line)<span.......>
, <p.......color: black...>
or <span.......color: black...>
(?s-i)(?:<(?:p|li\s*style)[^>]*?color:\s*black[^>]*?>\s*<span[^>]*?>\s*|<(?:p|span)[^>]*?color:\s*black[^>]*?>\s*)<code\s*style="background-color:\s*transparent;">(*SKIP)(*F)|<code\s*style="background-color:\s*transparent;">
However, this Regular expression is more accurate as it finds only <p.....
and <li.....`
(?:<(?:p|li)\b[^>]*?color\s*:\s*(?:(black))[^>]*?>(?(1)(?:\s*<span\b[^>]*?>)?)|<span\b[^>]*?color\s*:\s*black[^>]*?>)(?s)\s*<code\b(?:".*?"|'.*?'|[^>]*?)+>(*SKIP)(*FAIL)|<code\b[^>]*?style[^>]*?background-color\s*:\s*transparent[^>]*?>
See https://regex101.com/r/j5eyZ1/1 to understand what is matched
If only the block of matter posted at the beginning, right at the top of this thread is to be considered (Regular expression negative lookbehind for two strings), this Regular expression is enough (see https://regex101.com/r/YrH2vn/1 for evidence):-
(?:<(?:p)\b[^>]*?color\s*:\s*(?:(black))[^>]*?>(?(1)(?:\s*<span\b[^>]*?>)?)|<span\b[^>]*?color\s*:\s*black[^>]*?>)(?s)\s*<code\b(?:".*?"|'.*?'|[^>]*?)+>(*SKIP)(*FAIL)|<code\b[^>]*?style[^>]*?background-color\s*:\s*transparent[^>]*?>