I have a question about Matcher. If there are two capturing group that can be satisfied, which one will it choose?
Let's say the pattern is (A|AB|B), if matcher is input with "AB", will it satisfy the A group then the B group or the AB group?
Asked
Active
Viewed 104 times
2
roblovelock
- 1,971
- 2
- 23
- 41
liu hp
- 21
- 1
-
Did you try this example?. It should be simple enough to test. – TheLostMind Feb 05 '15 at 13:23
-
It matches the first, not the longest. See: http://stackoverflow.com/questions/4515309/java-regex-alternation-operator-behavior-seems-broken – ᴇʟᴇvᴀтᴇ Feb 05 '15 at 13:24