62,623
社区成员
发帖
与我相关
我的任务
分享import java.util.Pattern;
import java.util.Matcher;
public class Test {
public static void main(String[] args) {
String str = "<a href=\"11\"> <font color=\"21\">aaa </font> </a>" +
"<a href=\"12\"> <font color=\"22\">bbb </font> </a>" +
"<a href=\"13\">ccc </a> " +
"<a href=\"14\"> <font color=\"23\">ddd </font> </a>" +
"<a href=\"15\"> <font color=\"25\">eee </font> </a> " +
"<a href=\"16\">fff </a> ";
String regex = "<a[^>]*>(?:\\s*<font[^>]*>)?(.*?)(?:</font>\\s*)?</a>";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
while(matcher.find()) {
System.out.println(matcher.group(1));
}
}
}package test1;
import java.util.regex.*;
public class Test6
{
public static void main(String[] args)
{
String s="<a href=\"11\"> <font color=\"21\">aaa </font> </a> "
+"<a href=\"12\"> <font color=\"22\">bbb </font> </a> "
+"<a href=\"13\">ccc </a> "
+"<a href=\"14\"> <font color=\"23\">ddd </font> </a>"
+"<a href=\"15\"> <font color=\"25\">eee </font> </a> "
+"<a href=\"16\">fff </a> ";
String regex="<a.*?>(.*?)</a>";
Pattern pt=Pattern.compile(regex);
Matcher mt=pt.matcher(s);
while(mt.find())
{
System.out.println(mt.group(1).replaceAll("<font.*?>|</font>", "").trim());
}
}
}
/**
* kimi
*/
package test;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* @author kimi
*
*/
public class TestCsdn {
/*
* <a href="11"> <font color="21">aaa </font> </a> <a href="12"> <font color="22">bbb </font> </a> <a href="13">ccc
* </a> <a href="14"> <font color="24">ddd </font> </a> <a href="15"> <font color="25">eee </font> </a> <a
* href="16">fff </a>
*
*/
/**
* @param args
*/
public static void main(String[] args) {
String s1 = "<a href=\"11\"> <font color=\"21\">aaa </font> </a>\n"
+ "<a href=\"12\"> <font color=\"22\">bbb </font> </a>\n" + "<a href=\"13\">ccc </a>";
String s = "(<a href=\"\\d{2}\">(<font color=\"\\d{2}\">(.*?)</font>)?|(.*?)</a>[\n\r]?)+";
Pattern p = Pattern.compile(s);
Matcher m = p.matcher(s1);
if (m.matches()) {
System.out.println("ok");
}
}
}