When using a regular expression, it is important to remember that there is an implicit AND operator at work. This can be seen from the JavaDoc for java.util.regex.Pattern , covering the logical operators:
Logical operators
XY X followed by Y
X | Y either X or Y
(X) X, as a capture group
This AND takes precedence over OR in the second pattern. The second pattern is equivalent to (?:Yes)|(?:(?:No)(.*)End) .
For it to be equivalent to the first pattern, it must be changed to
(?:(?:Yes)|(?:No))(.*)End
Jacob Tomaw
source share