I'm pretty new to regex, but I did some study. I got into a problem that might turn out impossible to be solved by regex, so I need a piece of advice.
I have the following string:
some text key 12, 32, 311 ,465 and 345. some other text dog 612,
12, 32, 9 and 10. some text key 1, 2.
I'm trying to figure if it possible (using regex only) to extract the numbers 12
32
311
465
345
1
2
only - as a set of individual matches.
When I approach this problem I tried to look for a pattern that matches only the relevant results. So I came up with :
- get numbers that have prefix of "key" and NOT have prefix of "dog".
But I'm not sure if it is even possible. I mean that I know that for the number 1
I can use (?<=key )+[\d]+
and get it as a result, but for the rest of the numbers (i.e. 2..5
), can I "use" the key
prefix again?