【发布时间】:2019-09-19 09:50:58
【问题描述】:
我收到java.lang.IllegalArgumentException:非法组引用
对于以下程序
public static void main(String args[]) {
String finalQueryString = "TAC: (dash_board or platform* or interfac* or portal* or app or (computer w5 (application or instruction*)) or program or software) and (educat* or ((work* or workforce or employment or job or career) w5 (skill or profile or expertise or abilit* or proficien* or competence or experience)) or train* or certifi*) and ((rank* or scor* or grad* or rate* or rating) w9 (educat* or skill or profile or expertise or abilit* or proficien* or competence or train* or certifi*)) and AC: (G06Q10/063112 or G06Q10/1053$) ";
System.out.println(String.format("(%s)", finalQueryString.trim()));
String matchedValue = "L12";
System.out.println(String.format("((?<!\\w)%s(?!\\w))", matchedValue));
String parsedQuery = "SC:L12 not SC:L11";
parsedQuery = parsedQuery.replaceAll(String.format("((?<!\\w)%s(?!\\w))", matchedValue), String.format("(%s)", finalQueryString.trim()));
System.out.println(parsedQuery);
}
在 parsedQuery Line 我收到 Illegal group reference 异常,我无法弄清楚为什么会发生这种情况,有人可以解决这个问题吗?
【问题讨论】:
-
你需要转义
finalQueryString中的$,例如通过Matcher.quoteReplacement( finalQueryString )
标签: java