日期:2014-05-17 浏览次数:20887 次
str="$a$=1 and $b$=2";
String str="$a$=1 and $b$=2";
str = str.replaceAll("[$]{1}[^$]*[$]{1}", "");
System.out.println(str);
------解决方案--------------------
str.replaceAll("\\$.*?\\$", "");
这样ok?
------解决方案--------------------
String str="$a$=1 and $b$=2";
Pattern p = Pattern.compile("(?<=\\$)=[^\\$]*");
Matcher m = p.matcher(str);
while(m.find()){
System.out.println(m.group());
}
------解决方案--------------------
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));
}
------解决方案--------------------
这个明显用 split 来做比较好啊, 再说js里面好像没replaceAll这个方法吧
------解决方案--------------------
不知道LZ想得到什么结果?看看是不是这个意思?
var str="$a$=1 and $b$=2";
var r1 = str.replace(/\$.*?\$(=.*?)/g, "$1");
var r2 = str.replace(/.*?(\$.*?\$)=\w*/g, "$1");
alert(r1);
alert(r2);