Html源码:
<property name="name">
projectNo
</property>
<property name="property">
projectNo
</property>
<property name="label">
项目编号
</property>
<editor />
获取上面代码中的“项目编号”
使用正则表达式:
pattern = Pattern.compile("[\\s\\S]*?name=\"label\">[\\s\\S]*?(.*?)[\\S\\s]*?</property>[\\s\\S]*?");
System .out.println(matcher.matches());
System .out.println(matcher.group(1));
返回True,但是matcher.group(1)中无内容。请问上面的正则表达式哪里有问题。
你好:
正则可以这样写
pattern = Pattern.compile("[\\s\\S]*?name=\"label\">(.*?)</property>[\\s\\S]*?");追问你好,我用了你写的正则表达式,matcher.matches()返回的是false。
追答根据你的写的,
String string = "<property name=\"label\">项目编号</property><editor />";结果:
string=项目编号
true
追问恩,我把单独的项目编号提取出来放在一个String中,使用你的正则表达式是可以的,但是放在字符串中:
...
项目编号
...
就是错误的