求一正则表达式(问题解决立刻结贴——在线等)
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);