I am trying to match multiple inputs in the same regex to capture the number following.
If the input doesnt match the first group then I have issues because all previous capture groups are still captured despite it doesnt match they group. I believe I need to use a lookaround
assertion, but I am not familiar with those.
Sample input:
wordA 123456
wordA: 123456
wordA : 123456
wordA R123465
wordA: R123456
wordA : R123456
wordB R123465
WordA has both optional :
and R
. So far I have this: /(?:wordA :?R?(\d+)|wordB R(\d+))/i
.
Using the last sample input provides this result:
array
0 => string 'wordB R123456' (length=13)
1 => string '' (length=0)
2 => string '123456' (length=6)
Wanted result is:
array
0 => string 'wordB R123465' (length=13)
1 => string '123456' (length=6)
Any ideas how to fix ?