问题
I have this text:
x A1 ,A2-A4 xx, xxx A5 xxxx
I have this regular expression:
[A-Z]{1,3}-?\d{1,3}
It gets 4 matches:
A1,A2,A4,A5
But I need to modify this regular expression to get these 3 matches:
A1,A2-A4,A5
Can anyone help me?
回答1:
Just double the expression:
[A-Z]{1,3}-?\d{1,3}(?:-[A-Z]{1,3}-?\d{1,3})?
Demo
来源:https://stackoverflow.com/questions/29124643/how-to-include-character-in-regular-expression