We're updating the issue view to help you get more done. 

Named group index is incorrect after parens in a character class

Description

johnlcox@github writes:

Parenthesis in a character class don't need to be escaped in a regex string. The Pattern#countOpenParens function does not account for this, and will count parenthesis in a character class as a group. This leads to the index being off for all named groups following the character class.

Here is a unit test that will fail due to this:

1 2 3 4 5 @Test public void testIndexOfNamedGroupAfterNonEscapedParenInCharacterClass() { Pattern p = Pattern.compile("(a)(?<foo>[()])(?:c)(?<named>x)"); assertEquals(2, p.indexOf("named")); }

Environment

None

Status

Assignee

TonyT

Reporter

TonyT

Labels

None

Fix versions

Affects versions

0.1.9
0.1.2
0.1.4
0.1.3
0.2.1
0.1.6
0.1.5
0.1.10
0.1.8
0.1.7

Priority

Major