3 ms·
It's a Regular Language, in the mathematical sense. All you need is the greedy match anything sequence, I don't know why so many people jumped to non-Regular re
by dumbo-octopus 3y ago
It's a Regular Language, in the mathematical sense. All you need is the greedy match anything sequence, I don't know why so many people jumped to non-Regular regex extensions.
- 63 3y agoI'm sorry I'm not familiar with the mathematics behind regular expressions. Can you give an example of what your approach would look like?
- dumbo-octopus 3y agofirst = line.match( /(?:(0|zero)|(1|one) ... (9|nine))/) last = line.match(/.*(?:(0|zero)|(1|one) ... (9|nine))/) indexOfGroupMatched = ([_, ...groups]) => groups.findIndex(x => x != undefined) num = +[first, last].map(indexOfGroupMatched).join('')
- 63 3y agoOh I understand. That's a good idea. Honestly I only ever use regex for AOC so I never would've thought of using it like that. I'll keep it in mind. Thanks!