Hacker News
new
|
past
|
comments
|
ask
|
show
|
jobs
|
submit
login
torbencarstens
on Dec 1, 2023
|
parent
|
context
|
favorite
| on:
Advent of Code 2023 is nigh
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
Huppie
on Dec 1, 2023
[–]
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.
dumbo-octopus
on Dec 1, 2023
|
parent
[–]
Or just tack a greedy anything-matcher to the front of the regex: .*(?: ... )
Guidelines
|
FAQ
|
Lists
|
API
|
Security
|
Legal
|
Apply to YC
|
Contact
Search:
[0] https://www.regular-expressions.info/lookaround.html