Hacker News new | past | comments | ask | show | jobs | submit login

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




Another 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.


Or just tack a greedy anything-matcher to the front of the regex: .*(?: ... )




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: