Assume the following strings:
A01B100A01.B100A01A01............................B100( whatever between A and B )
The thing is, the numbers should be \d+, and in all of the strings A will always be present, while B may not. A will always be followed by one or more digits, and so will B, if present. What regex could I use to capture A and B’s digit?
I have the following regex:
(A(\d+)).*?(B?(\d+)?)
but this only works for the first and the third case.
AprecedeB? Assuming yes.Bappear more than once? Assuming no.Bappear except as part of aB-number group? Assuming no.Then,
using the lazy .*? or
which is more efficient but requires that
Bbe a single character.EDIT: Upon further reflection, I have parenthesized the patterns in a less-than-perfect way. The following patterns should require fewer assumptions: