4 ms·
Wait, in non-multiline mode, it only matches _one_ trailing newline? And not any other whitespace, including \r or \r\n? That is indeed surprising behavior. Why
by aftbit 3y ago
Wait, in non-multiline mode, it only matches _one_ trailing newline? And not any other whitespace, including \r or \r\n? That is indeed surprising behavior. Why? Why not just make it end of string like the author expected?
>>> import re
>>> bool(re.search('abc$', 'abc'))
True
>>> bool(re.search('abc$', 'abc\n'))
True
>>> bool(re.search('abc$', 'abc\n\n'))
False
>>> bool(re.search('abc$', 'abc '))
False
>>> bool(re.search('abc$', 'abc\t'))
False
>>> bool(re.search('abc$', 'abc\r'))
False
>>> bool(re.search('abc$', 'abc\r\n'))
False