81,092
社区成员
发帖
与我相关
我的任务
分享
str="$a$=1 and $b$=2";
var str="$a$=1 and $b$=2";
console.log(str.replace(/(\$\w+\$)/g, ""));//output: =1 and =2
console.log(str.split(/\$\w+\$/));//output: [ '', '=1 and ', '=2' ]
var str="$a:$=1 and $b:$=2:2";
var r1 = str.replace(/(.*?\$.*?\$=[^\s]*):(.*?)/g, "$1:$2");
alert(r1);
var str="$a$=1 and $b$=2";
var r1 = str.replace(/\$.*?\$(=.*?)/g, "$1");
var r2 = str.replace(/.*?(\$.*?\$)=\w*/g, "$1");
alert(r1);
alert(r2);
var str="$a$=1 and $b$=2";
var result = str.replace(/\$.*?\$(=.*?)/g, "$1");
alert(result);
function run(){
var str="$a$=1 and $b$=2";
var reg = /[$]{1}[^$]*[$]{1}/;
var str2 = str;
var str3 = "";
while(true){
str3 = str2.replace(reg,"");
if(str2 == str3){
break;
}
str2 = str3;
}
alert(str);//原字符串
alert(str2);//抽取出的字符串
}
String res = "str=\"$a$=1 and $b$=2\"";//(?<=\\$)=[^\\$]*
Pattern p = Pattern.compile("\\$(.*?)\\$(=[^\\$\"]*)");
Matcher m = p.matcher(res);
while (m.find()) {
System.out.println(m.group(2));
}
String str="$a$=1 and $b$=2";
Pattern p = Pattern.compile("(?<=\\$)=[^\\$]*");
Matcher m = p.matcher(str);
while(m.find()){
System.out.println(m.group());
}