3 ms·
and what's the use case for that? The main problem here is that you can't chain re.match().group() because None has no .group() Why do you want to match empty
by est 8y ago
and what's the use case for that?
The main problem here is that you can't chain re.match().group() because None has no .group()
Why do you want to match empty string with a group?
- yorwba 8y agoThe use case for a regular expression that matches the empty string is detecting whether something starts with an optional pattern. E.g. '(foo)?' to match the optional prefix 'foo'. FWIW if you really want re.match().group() to always return a string, you can just wrap all your regular expressions with '(...)?'. The reason why someone might want to be able to distinguish between "no match" and "the match is empty" is writing code that takes any arbitrary regular expression and uses it as a filter. Then someone else could pass in an expression that matches empty and everything works together nicely.