我将值存储在键/值哈希图中。当键的值以 $ 开头时,我执行了一个正则表达式 replaceAll 调用,会引发异常。知道为什么以及如何防止这种异常吗?当值包含/以“普通”文本开头时没有错误
public static String ReplaceVariables(String argumentValue){
Pattern p = Pattern.compile("\\$\\{.*?\\}"); // find any text surrendered by "${" and "}"
while (true)
{
Matcher m = p.matcher(argumentValue);
if (!m.find()){
break; // no match found
}
String varName = m.group();
String varValue = GlobalUtilities.getVariable(varName); //get the hashmap value of the "varName" key
argumentValue = m.replaceAll(varValue); // replace all ${....} found by its hashmap value
}
return argumentValue; // return the new string
}