您使用的工具具有 actionscript 正则表达式语法,这似乎与 java sytax 不同。
一个可行的解决方案可能是:X: ([0-9]+). Y: ([0-9]+)(?::inherit=(true|false))?
这是一个工作示例:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class plop {
/**
* @param args
*/
public static void main(String[] args) {
String regex = "X: ([0-9]+). Y: ([0-9]+)(?::inherit=(true|false))?";
String[] elem = new String [] {
"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)"
};
for (String s : elem) {
Pattern compile = Pattern.compile(regex);
Matcher matcher = compile.matcher(s);
if (matcher.find()) {
System.out.print("'"+matcher.group(0)+"'");
System.out.print(", X:"+matcher.group(1));
System.out.print(", Y:"+matcher.group(2));
if (matcher.group(3) !=null)
System.out.print(", inherit:"+matcher.group(3));
System.out.println();
}
}
}
}
结果:
'X: 192131, Y: 1923123', X:192131, Y:1923123
'X: 192131, Y: 1923123:inherit=true', X:192131, Y:1923123, inherit:true
'X: 192131, Y: 1923123:inherit=false', X:192131, Y:1923123, inherit:false