The bug is some strings can have overlapping characters.
onEight threEight fivEight. There are more cases.
So if you do a search and replace your string becomes 1ight 3ight and the second number does not get found.
Possible fixes:
Search and replace and add the extra letter: oneEigh then search and replace.
Search and replace words to numbers but put some extra letters in just in case.
I believe everyone gets different input and needs to produce a different result.
There can be multiple solutions.
Do you process as you are going, or do you parse and build a data structure to process later so you loop through the results multiple times.
My solution was worse than most: replace one -> one1one
You are only going to do the replace all for each number and if the "e" is also in eight it is still there for the next set of replace.
A better quick and dirty solution from Mastodon was to just add the common character first:
twone -> twoone
First and last number, so loop through the characters, ask is it a letter or a number.
Find the first and last number in the string and add the strings together and convert it to a number.
So you find a 3,4,5 in the line so find the first in the result is 3 and 5 is the last so it becomes 35.
The bug is some strings can have overlapping characters. onEight threEight fivEight. There are more cases. So if you do a search and replace your string becomes 1ight 3ight and the second number does not get found.
Possible fixes: Search and replace and add the extra letter: oneEigh then search and replace. Search and replace words to numbers but put some extra letters in just in case.