4 ms·
Sometimes you just check for a match (e.g.of entire string) and define no groups. The problem is not in re.match but in None being a relatively poor Maybe / Op
by nine_k 7y ago
Sometimes you just check for a match (e.g.of entire string) and define no groups.
The problem is not in re.match but in None being a relatively poor Maybe / Optional (still ways better than C-style `null` of many other languages).
- est 7y ago> Sometimes you just check for a match re.match vs re.search
- deleted 7y ago[deleted]
- Liquid_Fire 7y agore.search is different. re.match matches from the beginning of the string, while re.search matches from anywhere in the string.
- geofft 7y agoCould just have been if re.match(...).matched: But yeah, agree that Optional is what I want here. if let Some(m) := re.match(...) m.group(1)... m = re.match(...) m.group(1) # TypeError because I haven't unwrapped the Optional In current Python, that last line sometimes throws a runtime error.