79557759

Date: 2025-04-06 03:16:42
Score: 1.5
Natty:
Report link

I see that your second alternation (?:<span[^>]*?color: black.*?>[\S\s\n]*?<code) is open ended. This pattern will cause the regex engine to keep looking for the next <code until 'the end of time', with [\S\s\n]*?. It may be a factor in getting the error:

"Invalid Regular expression": "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."

I noticed that, not only is the <code> element we want to skip preceded by <p> or <span> elements with style="color: black, but they are inside these elements.

So, this pattern below looks to skip the entire <p> or <span> elements were the style="color: black" is true for the element. It works with the test string you provided.

I am curious to see if this pattern/approach solves the issue. Please let me know.

REGEX PATTERN (PCRE2 Flavor; Flags:gms)

(?s)(?:<(p|span)[^>]*?color: black[^>]*>.*?<\/\1)(*SKIP)(*F)|<code\s*style="background-color:\s*transparent;">

Regex Demo: https://regex101.com/r/ebwZLJ/8

REGEX NOTES:

For reference, here is the regex pattern from the Question (https://regex101.com/r/kIm0bl/1)

Reasons:
  • RegEx Blacklisted phrase (2.5): Please let me know
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: rich neadle