每当看到),
实际输入:
(brb = 0069 of Clinic = Clinic Name 006uh9)(brb = 07hvh03 of Clinic =
Clinic 0703)(brb = 0703 of Clinic = Clinic1)
预期产出:
(brb = 0069 of Clinic = Clinic Name 006uh9)
(brb = 07hvh03 of Clinic = Clinic 0703)
每当我在做string.replaceAll()时,它都在说
'/) no match found' error.
任何帮助将不胜感激。
errorMsgArray.push(errorMsg);
if(errorMsgArray.length > 0){
for(i=0;i<errorMsgArray.length;i++){
var arr=errorMsgArray[i].split(',');
for(i=0;i<arr.length;i++){
errorMessage+="("+"brb = "+arr[i]+")";
finalMessage =errorMessage.replace('[',"");
finalMessage = finalMessage.replace(']',"");
finalMessage=finalMessage.replaceAll('-',"of Clinic = ");
$("#forceUpdateMsg").text(finalMessage + " is/are within zip
code " + inputData.updatedBy + " and will be changed to zip
code " + inputData.zipCode + ". Proceed (Y/N)?"
答案 0 :(得分:1)
假设您的输入为(...)(...)(...)
,并且您希望在\n
和)
之间插入(
,则应使用正则表达式。
var input = "(hjj = 0069 of Clinic = Clinic Name 006uh9)(bjb = 07hvh03 of Clinic = Clinic 0703)(vhvh = 0703 of Clinic = Clinic1)"
var output = input.replace(/\)\(/g, ')\n(')
console.log(output)
在正则表达式中,您应该转义(
和)
,因为它们是元字符。