我有一個字符串:如何逃避java中的正則表達式模式中的特殊字符?
Patient:
${ss.patient.howard.firstName} ${ss.patient.howard.lastName}
Gender: ${ss.patient.howard.sex}
Birthdate: ${ss.patient.howard.dob}
${ss.patient.howard.addressLine1}
Phone: (801)546-4765
,我試圖用其他字符串替換${..}
子所以它看起來像:
Patient:
firstName lastName
Gender:sex
Birthdate: dob
addressLine1
Phone: (801)546-4765
我想examleString.replaceFirst((字符串)TestcaseContext.getCache()。 get(matcher.group(1)))並獲取,非法重複索引1附近 \ $ {(。*?)\} –
可能是[This](http://stackoverflow.com/questions/10664434/escaping-特殊字符在Java正則表達式)將引導你在正確的方向? – cdp
你必須使用正則表達式嗎?我會考慮這個特定的[Apache Commons Lang StrSubstitutor](https://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/commons/lang3/text/StrSubstitutor.html)應用。它確實是你想要的。 – KevinO