3 ms·
> So if you're trying to match a string without a newline at the end, you can't only use $ in Python! My expectation was having multiline mode disabled wouldn't
by wodenokoto 3y ago
> So if you're trying to match a string without a newline at the end, you can't only use $ in Python! My expectation was having multiline mode disabled wouldn't have had this newline-matching behavior, but that isn't the case.
A reproducible example would be nice. I don’t understand what it is he cannot do. `re.search('$', 'no new lines')` returns a match.
- iainmerrick 3y agoThis unexpectedly matches: re.match('^bob$', 'bob\n') I didn't want the trailing newline to be included.
- wodenokoto 3y agoBut that string does have a new line at the end.
- iainmerrick 3y agore.match('^bob$', 'bob') → yes re.match('^bob$', 'bobs') → no Most people would expect 'bob\n' not to match, because I used '$' and it has an extra character at the end, just like 'bobs'. In Python it does match because '\n' is a special case.
- rerdavies 3y ago... for some arbitrary definition of "most people".
- iainmerrick 3y agoThat’s true, probably fewer than ten million people in the world would have an opinion one way or the other. :)