I'd like to search for lines that don't start with a pound sign (#) on indented code.
Currently, I'm using the regex ^\s*([^\s#].*)
with multiline option on.
My problem is that on non commented lines it works perfectly.
On commented lines the regex engine performs a backtrack due to \s*
all the way from the comment sign to the start of the line, which can sometimes cause 40 or 50 backtrack steps.
The regex works perfectly on python code. It's just not very efficient due to the backtracking caused by the engine.
Any idea as of how to avoid it?
Bonus: It's rather funny that the regex engine doesn't recognize the fact that it's searching for [^\s]
one by one in \s*
and causes this amount of backtracking. What are the challenges in making the re engine work so?
Bonus 2: Using only the stdlib re module. As I cannot add 3rd parties. (I'm technically searching using sublime text but want to know how to generally do it in Python)