I created the following conditional regex which seems to work at http://gskinner.com/RegExr/ but doesn’t compile in Java.
The regex is as follows :
X: (\d+). Y: (\d+)(?(?=:inherit=(true|false)))
And it is supposed to pull my X, Y value and (if exists) the value followed by the :inherit=
e.g
X: 192131, Y: 1923123 (matches 192131, 1923123)
X: 192131, Y: 1923123:inherit=true (matches 192131, 1923123, true)
X: 192131, Y: 1923123:inherit=false (matches 192131, 1923123, false)
In Java I get an error:
Unknown inline modifier near index 20 X: (\d+). Y: (\d+)(?(?=:inherit=(true|false)))
With index 20 being the second parenthesis in (?(?
Can someone help me get it right in Java, and maybe also explain why the website tester processes it.
Thanks!
(?(is not a valid syntax.Use:
You need to escape
\.