With the test string:
This is a string1 string2 string3 string4 string5 string6 string7 so it is.
Is it possible to get all the stringXs as backreferences? Currently what I've tried ends up overwriting each time so I end up with one match - the last one.
For instance using a regex like this:
/This is a (?:(string\d) )+so it is./
Would always end up with a match of string7
at the end.
The best I've found so far is to remove the ?:
above and explode on the spaces, but I'd be interested in whether there's a way to do it purely with regex.
update specifically to PHP, what would be the best way to achieve this?