Because /g is just the repetition of the regex, and it may not be possible in some circumstances, I think
It could be perfectly feasible to have a regex like:
/^\w+\s+(?:(\d+)\s+){3}\w+$/
So I want a word, 3 group of digits and a word. But right now I don't know how to get the 3 values for the group of numbers. So I usually do something like:
/^\w+\s+(\d+)\s+(\d+)\s+(\d+)\s+\w+$/
that doesn't look so good. In extreme cases n can be far bigger than 3 and I should get the whole string of numbers and then split them. Also, if I want instead of just n repetitions to force a threshold ({3,10} for example) then I'm at a loss and I have to implement it in two steps.
I know that may be even clearer than the regex I'm trying to write, but I'm just curious about it. I'd like my regex to fit as as much as possible the format of my input and get the values straightforwardly. Don't know if it can be done though. That's my question.
There's no real problem behind, nor real output either. It's just something I've found several times and I've never been happy with the solutions I've implemented.
Hope it makes more sense now,
Thanks |