JavaVerbalExpressions
JavaVerbalExpressions copied to clipboard
or() with capture()
It seems to me that the following expression:
VerbalExpression testRegex = regex()
.capture()
.find("abc")
.or("def")
.build();
should evaluate to the regex: /(?:((?:abc)|(?:(?:def))))/
, but instead it evaluates to: /(?:((?:abc))|(?:(?:def)))/
. As a result, if we test this expression against the string "def" it produces a match but no group is captured. This happens because the implementation of or() closes any opening parenthesis it finds in the string that precedes it.
I don't know why or() was implemented this way, but I believe the implementation of oneOf() I propose in https://github.com/VerbalExpressions/JavaVerbalExpressions/pull/31 may fix this problem.