Demo: https://regex101.com/r/5EVbAJ/1
I have this regexp:
a.+?(W)?.*?(\d)
My intention: get the character W as group, if the character exists in the string. Otherwise return empty group. Second group is an existing number which needs to be matched, as well.
My test data:
1. a,W1
2. a W1
3. a,W 1
4. a, V1
5. a, W1 //fail
1-3 work because there is only one character between the a and the W (I believe that's because of the lazy +? operator). 4 works because no W needs to be matched.
But 5 is not working: The number group is matched correctly, but the W group is empty, although a W occurs with 2 characters between a and W.
How can I get it fixed?