When performing a regex search in Python, even when re.MULTILINE
isn't enabled,
The expression A[\s]B
will match against
A
B
Since a newline matches \s
.
Besides splitting the string into lines and operating on each - Is there an efficient way to make the expressions delimit on newlines?
Edit: I know its possible to use [\t ]
or [^\S\r\n]
, the issue is I don't control the input in this case, users will enter \s
and won't expect it to spand lines. I'm not interested to try to tell the users they are wrong, from their perspective this is a bug.
So if the answer is "it can't be done without splitting lines" - so be it.
Note that operating on a file line by line is approximately twice as slow in my tests.