如下:
String str="要提取的内容";
<div class="out" onclick="' +this.name+'.bbb(this)" onmouseover="' +this.name+'.ccc(this,\'over\')" onmouseout="' +this.name+'.dddd(this,\'out\')">' +str+ '</div>';
现在我要写一个正则表达式要取出<div></div>之间的字符请问该怎么写,拜托各位大虾了!!!
String str="要提取的内容";
<div class="out" onclick="' +this.name+'.bbb(this)" onmouseover="' +this.name+'.ccc(this,\'over\')" onmouseout="' +this.name+'.dddd(this,\'out\')">' +str+ '</div>';
现在我要写一个正则表达式要取出<div></div>之间的字符请问该怎么写,拜托各位大虾了!!!
Pattern p = Pattern.compile("(<div .*?>)(.*)(</div>)");
Matcher m = p.matcher(div);
if(m.find()){
System.out.println(m.group(2));
}输出abcde
Matcher m = p.matcher(目标串);
m.find();
String str = m.group(2);
var reg = /<div .*>([^\</]*)<\/div>/g
alert(reg.test(str))
alert(RegExp.$1)
Matcher m = p.matcher(目标串);
m.find();
String str = m.group(2);
var A="a";
var str="asdasda"
<div class="out" onclick="' +this.name+'.bbb(this)" onmouseover="' +this.name+'.ccc(this,\'over\')" onmouseout="' +this.name+'.dddd(this,\'out\')">' +str+ ' </div>';
现在我要写一个正则表达式要取出 <div> </div>之间和变量a相匹配的字符,并把该字符替换成<Strong>A</strong>请问该怎么写,拜托各位大虾了!!!
Matcher m = p.matcher(目标串);
m.find();
String str = m.group(2);
str.replaceAll("</?div[^>]*>","");
Matcher m = p.matcher(目标串);
m.find();
String str = m.group(2);
String a = "........";Pattern p2 = Pattern.compile(a);
matcher m2 = p2.matcher(str);
System.out.println(m2.replaceAll("<strong>"+a+"</strong>"));
str是你以前的<div>的字符串
str=str.replaceAll("</?div[^>]*>","");
String newStr=str.replace(str,"<strong>'"+A+"'</strong>");
var a="a";
var str="abcdefg";
<div class="out" onclick="' +this.name+'.bbb(this)" onmouseover="' +this.name+'.ccc(this,\'over\')" onmouseout="' +this.name+'.dddd(this,\'out\')">' +str+ ' </div>'; 匹配和替换后得到的最后结果是
<div class="out" onclick="' +this.name+'.bbb(this)" onmouseover="' +this.name+'.ccc(this,\'over\')" onmouseout="' +this.name+'.dddd(this,\'out\')">' <strong>a</strong>bcdefg'</div>';
public class Test {
public static void main(String[] args){
String A="a";
String str="abcdefg";
String str1="<div>"+str+"</div>;";
Pattern p=Pattern.compile("<div[^>]*>(.[^>]*)</div>");
Matcher m=p.matcher(str1);
if(m.find())
System.out.println(str1.replace(m.group(1), m.group(1).replaceAll(A,"<strong>a</strong>")));
}
}
你这里的 就是"a" 把所有 "a"都换成 <strong>a</strong>9楼的那个 测试成功。 JS只知皮毛。。
var a="a";
var str="abcdefg";
<div class="out" onclick="' +this.name+'.bbb(this)" onmouseover="' +this.name+'.ccc(this,\'over\')" onmouseout="' +this.name+'.dddd(this,\'out\')">' +str+ ' </div>'; 匹配和替换后想要得到的最后结果是
<div class="out" onclick="' +this.name+'.bbb(this)" onmouseover="' +this.name+'.ccc(this,\'over\')" onmouseout="' +this.name+'.dddd(this,\'out\')">' <strong>a </strong>bcdefg' </div>';
<strong>a </strong;
Matcher m = p.matcher(目标串);
m.find();
String str = m.group(2);
String a = "a"; Pattern p2 = Pattern.compile(a);
Matcher m2 = p2.matcher(str);
String str2 = m2.replaceAll("<strong>"+a+"</strong>");
Pattern p3 = Pattern.compile(str);
Matcher m3 = p3.matcher(目标串);
m3.find();
StringBuffer sb = new StringBuffer();
m3.appendReplacement(sb, str2);
m3.appendTail(sb);
System.out.println(sb.toString());
div><font color="red">fsdfs</font></div>
13楼的对吗???测试完再说话。。
http://topic.csdn.net/u/20091116/13/00c6cfc8-28ce-4d7d-98cf-0fbb2f3dae39.html