3 ms·
Another option when using regex would be to use the lookahead[0] operator (as long as supported, which is the case for the python re module) (?=(one|two|thre
by torbencarstens 3y ago
Another option when using regex would be to use the lookahead[0] operator (as long as supported, which is the case for the python re module)
(?=(one|two|three|[...]))
would return `["two", "one"]` for the input string `twone` since the lookahead operator doesn't consume the next character.
[0] https://www.regular-expressions.info/lookaround.html https://www.regular-expressions.info/lookaround.html
- Huppie 3y agoAnother trick is you can put some regex engines in right-to-left mode, so my lazy (and admittedly relatively expensive cpu-wise) solution was to match ltr for first and rtl for last.
- dumbo-octopus 3y agoOr just tack a greedy anything-matcher to the front of the regex: .*(?: ... )