I know how to solve this in a not so elegant way, but somehow I have the feeling I am missing something obvious.
What I want is this: I've got a couple (possibly 1000's) of regexps. I want to go through a string, each time finding the first regexp that matches, and returning some relevant bit that matched, plus a string of which regexp it was that matched.
So, let's say if regexp 1 matched, I want to return $4 (relevant to that first regexp that is), and the string 'FIRST'. If the second one matched I want to return $2, and 'SECOND', e.g.
And preferrable of course I want to go through the string just once, and do the matching just once...
What I want is this: I've got a couple (possibly 1000's) of regexps. I want to go through a string, each time finding the first regexp that matches, and returning some relevant bit that matched, plus a string of which regexp it was that matched.
So, let's say if regexp 1 matched, I want to return $4 (relevant to that first regexp that is), and the string 'FIRST'. If the second one matched I want to return $2, and 'SECOND', e.g.
And preferrable of course I want to go through the string just once, and do the matching just once...