I have some code using Oracle regex that I want to port to GWT.
public static void main( String[] args )
{
String expression = "(abc)|(def)";
String source = "abcdef";
Pattern pattern = Pattern.compile(expression);
Matcher matcher = pattern.matcher(source);
while (matcher.find())
{
if (matcher.start(1) != -1)
{
// it's an "abc" match
}
else if (matcher.start(2) != -1)
{
// it's a "def" match
}
else
{
// error
continue;
}
int start = matcher.start();
int end = matcher.end();
String substring = source.substring(start, end);
System.out.println(substring);
}
}
I’ve tried porting it to the GWT regexp library, but it uses capturing groups through the start(int) method, which doesn’t seem to be supported in GWT regexp.
Is there a way to simulate this behaviour?
APIs references: