谁给我看看为什么这样匹配不到???正则表达式!

sidney553816092 2011-11-22 06:08:30
String a = "<font style=\"color=#104531\" size=+1><b>开往:碧沙湖</b></font>";
Pattern pt2 = Pattern.compile("(<font style=\"color=#104531\" size=+1>)(.*?)(</font>)");
Matcher mc2 = pt2.matcher(a);
if(mc2.find()){

}

我想要得到<b>..</b>中的内容,我这样匹配不行("(<font style=\"color=#104531\" size=+1>)(.*?)(</font>),不知道为什么??

求解,谢谢!
...全文
84 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
sidney553816092 2011-11-22
  • 打赏
  • 举报
回复
找到原因了,531\" size哎 少了一个空格 thank
sidney553816092 2011-11-22
  • 打赏
  • 举报
回复
咦,你看我的。我肯定试过才说的
public static void main(String[] args) throws Exception {

String a = "<font style=\"color=#104531\" size=+1><b>开往:碧沙湖</b></font>";
Pattern pt = Pattern.compile("(<font style=\"color=#104531\" size=\\+1>)(.*?)(</font>)");
Matcher mc = pt.matcher(a);
if(mc.find()){
System.out.println(mc.group(2));
}else{
System.out.println("没有找到!");
}
}
若鱼1919 2011-11-22
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 sidney553816092 的回复:]
引用 5 楼 goldenfish1919 的回复:
引用 3 楼 sidney553816092 的回复:
引用 1 楼 goldenfish1919 的回复:
Java code

public static void main(String[] args) {
String a = "<font style=\"color=#104531\" size=+1><b>开往:碧沙湖<……
[/Quote]





你丫不仅侮辱我的智商,你还侮辱我的人品!

你难道不知道我回帖子之前都会在自己的机器上先跑一边吗?

你金枝玉叶啊?就不能自己动松手!

fuck!

sidney553816092 2011-11-22
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 goldenfish1919 的回复:]
引用 3 楼 sidney553816092 的回复:
引用 1 楼 goldenfish1919 的回复:
Java code

public static void main(String[] args) {
String a = "<font style=\"color=#104531\" size=+1><b>开往:碧沙湖</b></font>";
Pattern pt2 = ……
[/Quote]

貌似你行? 别急大哥
若鱼1919 2011-11-22
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 sidney553816092 的回复:]
引用 1 楼 goldenfish1919 的回复:
Java code

public static void main(String[] args) {
String a = "<font style=\"color=#104531\" size=+1><b>开往:碧沙湖</b></font>";
Pattern pt2 = Pattern.compile("(<font style……

这个方法,我刚刚试了,貌似不行呵

[/Quote]

放屁!除非你用的是火星的jdk!



sidney553816092 2011-11-22
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 yousteely 的回复:]
Java code

String source = "<font style=\"color=#104531\" size=+1><b>开往:碧沙湖</b></font>";
Pattern pattern = Pattern.compile("<b>.*</b>");
Matcher matcher = pattern.matcher(source);
if(matcher.find……
[/Quote]

我并不是找<b>..</b>,首先需要找到 外面那层<font>
sidney553816092 2011-11-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 goldenfish1919 的回复:]
Java code

public static void main(String[] args) {
String a = "<font style=\"color=#104531\" size=+1><b>开往:碧沙湖</b></font>";
Pattern pt2 = Pattern.compile("(<font style=\"color=#10……
[/Quote]

这个方法,我刚刚试了,貌似不行呵
steely_chen 2011-11-22
  • 打赏
  • 举报
回复

String source = "<font style=\"color=#104531\" size=+1><b>开往:碧沙湖</b></font>";
Pattern pattern = Pattern.compile("<b>.*</b>");
Matcher matcher = pattern.matcher(source);
if(matcher.find()){
System.out.println(matcher.group().replace("<b>", "").replace("</b>", ""));
}
若鱼1919 2011-11-22
  • 打赏
  • 举报
回复

public static void main(String[] args) {
String a = "<font style=\"color=#104531\" size=+1><b>开往:碧沙湖</b></font>";
Pattern pt2 = Pattern.compile("(<font style=\"color=#104531\" size=\\+1>)(.*?)(</font>)");
Matcher mc2 = pt2.matcher(a);
if(mc2.find()){
System.out.println(mc2.group(2));
}
}

81,095

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧