正则表达式处理 字符串
Tag (0[0,0],6[0,6]): html
Tag (6[0,6],12[0,12]): head
Tag (12[0,12],19[0,19]): title
Txt (19[0,19],23[0,23]): 这是标题
End (23[0,23],31[0,31]): /title
End (31[0,31],31[0,31]): /head
Tag (31[0,31],37[0,37]): head
End (37[0,37],37[0,37]): /head
Tag (37[0,37],43[0,43]): body
Txt (43[0,43],49[0,49]): body部分
Tag (49[0,49],56[0,56]): table
Tag (56[0,56],60[0,60]): th
Txt (60[0,60],63[0,63]): 表头1
End (63[0,63],68[0,68]): /th
Tag (68[0,68],72[0,72]): td
Txt (72[0,72],78[0,78]): 表内容1.1
End (78[0,78],83[0,83]): /td
Tag (83[0,83],87[0,87]): td
Txt (87[0,87],93[0,93]): 表内容1.2
End (93[0,93],98[0,98]): /td
Txt (98[0,98],104[0,104]): 表内容1.3
Tag (104[0,104],108[0,108]): td
Txt (108[0,108],112[0,112]): 表内容三
End (112[0,112],117[0,117]): /td
Tag (117[0,117],124[0,124]): table
Tag (124[0,124],128[0,128]): th
Txt (128[0,128],131[0,131]): 表头2
End (131[0,131],136[0,136]): /th
Tag (136[0,136],140[0,140]): td
Txt (140[0,140],146[0,146]): 表内容2.1
End (146[0,146],151[0,151]): /td
Tag (151[0,151],155[0,155]): td
Txt (155[0,155],161[0,161]): 表内容2.2
End (161[0,161],166[0,166]): /td
Txt (166[0,166],172[0,172]): 表内容2.3
Tag (172[0,172],176[0,176]): td
Txt (176[0,176],180[0,180]): 表内容三
End (180[0,180],185[0,185]): /td
End (185[0,185],193[0,193]): /table
End (193[0,193],201[0,201]): /table
End (201[0,201],208[0,208]): /body
End (208[0,208],215[0,215]): /html
谁给个正则表达式
可以得到只剩下冒号以后的东西:
如
html
head
title
------解决方案--------------------顶,正则表达式的语法繁琐,不过用js就容易多了啊!
------解决方案--------------------Java code
import java.util.regex.*;
public class Test {
public static void main(String[] args) {
String str = "Tag (0[0,0],6[0,6]): html\nTag (6[0,6],12[0,12]): head\nTag (12[0,12],19[0,19]): title\nTxt (19[0,19],23[0,23]): 这是标题\nEnd (23[0,23],31[0,31]): /title";
System.out.println("---------------");
System.out.println(str);
System.out.println("---------------");
System.out.println();
Pattern pattern = Pattern.compile("[^:]*:([^:]*)$", Pattern.MULTILINE);
Matcher matcher = pattern.matcher(str);
while(matcher.find()) {
System.out.println(matcher.group(1));
}
}
}
------解决方案--------------------
Java code
import java.util.regex.*;
public class Test {
public static void main(String[] args) {
String str = "Tag (0[0,0],6[0,6]): html\nTag (6[0,6],12[0,12]): head\nTag (12[0,12],19[0,19]): title\nTxt (19[0,19],23[0,23]): 这是标题\nEnd (23[0,23],31[0,31]): /title";
System.out.println("---------------");
System.out.println(str);
System.out.println("---------------");
System.out.println();
Pattern pattern = Pattern.compile("[^:]*:([^:]*)$", Pattern.MULTILINE);
Matcher matcher = pattern.matcher(str);
String result = matcher.replaceAll("$1\n");
System.out.println(result);
}
}