Hacker News new | ask | show | jobs
by hypersoar 925 days ago
I heard the question was difficult before solving it, and then I was surprised when I didn't hit any speed bumps. The overlapping case didn't even occur to me. It turns out I stumbled upon a simple solution: use two regexes. One to match the first digit, and one to match the last. Then the overlapping is a total non-issue.
2 comments

Yeah, that's what I did for part 2 and there were no issues. I did try to solve it with a single regex at first, but for some reason I wasn't able to figure out the right combination of lazy/greedy matches to make it work (so I didn't even get far enough to discover the overlap issue).
If the whole numeric part of the string was something like "eightwo", I think that solution would fail.
It would only fail if you replace “eight” by “8”, but if you don’t replace anything then it will work fine
As a matter of fact, it does not.

https://mutraction.dev/link/c3