我正在用Java写一个正则表达式,但是运行程序时出现错误.
private final static Pattern QUOTE_VALUE = Pattern.compile("[_]?([a-zA-Z0-9_]+)=(\"[^]*\"),");
// Then later on down the road......
Macher m = QUOTE_VALUE.matcher(myString);
while (m.find()){
System.out.println("Found " + m.group(1) + " " + m.group(2));
}
我想使我的正则表达式匹配这些样本值.
_MyKey="ID IN [ "ABC" ]", // Note - it has a comma after the ]
_MyKey="ID IN [ ""XYZ"" ]", // Note - it has a comma after the ]
我使用在线正则表达式帮助程序进行了尝试-我的正则表达式实际上运行良好.但是当我在中运行程序时,出现此错误:
Caused by: java.util.regex.PatternSyntaxException: Unclosed character class near index 28
[_]?([a-zA-Z0-9_]+)=("[^]*"),
另一个问题是,我该如何格式化正则表达式,以便也可以将此字符串与之匹配?
MyKey="ID IN [ "ABC" ]", // without the _
_MyKey="ID IN [ "ABC" ]", // with the _
谢谢.
[编辑]
您能帮我解决这部分问题吗?
另一个问题是,我该如何格式化正则表达式,以便也可以将此字符串与之匹配?
MyKey =“ ID IN [” ABC“]”,//不带_
_MyKey =“ ID IN [” ABC“]”,//与_