当前位置: 代码迷 >> Java Web开发 >> <font>1<font>2<font>n</font></font></font>怎么能匹配到最外一层或所有嵌套层,n不定
  详细解决方案

<font>1<font>2<font>n</font></font></font>怎么能匹配到最外一层或所有嵌套层,n不定

热度:655   发布时间:2016-04-17 12:57:44.0
<font>1<font>2<font>n</font></font></font>,如何能匹配到最外一层或所有嵌套层,n不定。
<font> 1 <font> 2 <font> n </font> </font> </font> ,如何能匹配到最外一层或所有嵌套层,n不定。
<font> ((?! </?font> ).|( <font> ((?! </?font> ).)* </font> ))* </font>
只能匹配到固定层次的内容。
谢谢。

------解决方案--------------------
没明白
------解决方案--------------------
( "( <font> [1-9]+){0, "+n "}( </font> ){0, "+n+ "} ")

不是很正则表达式
------解决方案--------------------
有限自动机
------解决方案--------------------
String font= " <font> 1 <font> 2 <font> n </font> </font> </font> ";
Pattern p = Pattern.compile( "(? <= <font> )(.*?)(?= </?font> ) ");
Matcher m = p.matcher(font);
while(m.find())
System.out.println(m.group(1));

参考.
------解决方案--------------------
不是空的啊,我能打出1,2,n来.
------解决方案--------------------
是这样的吗?

------解决方案--------------------
String font= " <font> 1 <font> 2 <font> n </font> </font> </font> ";
Pattern p = Pattern.compile( "( <font> .* </font> ) ");
Matcher m = p.matcher(font);
while(m.find()){
System.out.println(m.group(1));
p=Pattern.compile( "(? <= <font> \\w)(.+)(?= </font> ) ");
m=p.matcher(m.group(1));
}

这样试试.
------解决方案--------------------
(? <= <font> \\w)(.+)(?= </font> ) 匹配中不包含 <font> \\w和 </font>
( <font> .* </font> )包含 <font> 和 </font>

------解决方案--------------------
http://www.unibetter.com/deerchao/zhengzhe-biaodashi-jiaocheng-se.htm

目录13
------解决方案--------------------
String font= " <font> 1 <font> 2 <font> n </font> </font> </font> a <font> b </font> ";
Pattern p = Pattern.compile( "(( <font> \\w)+( </font> )+) ");
Matcher m = p.matcher(font);
while(m.find()){

Matcher m1 = p.matcher(m.group(1));
while(m1.find()){
System.out.println(m1.group(1));
Pattern p1=Pattern.compile( "(? <= <font> \\w)(.+)(?= </font> ) ");
m1=p1.matcher(m1.group(1));
}
}
  相关解决方案