62,614
社区成员
发帖
与我相关
我的任务
分享
String b = " <td width=\"200\">[a] </td> <td>b </td> <td>[c] </td><td> fdas[d]fdsfd[e]fdasfdsa </td>";
String regex = "(?is)<td[^>]*>(?!(?:(?!\\[[^\\[\\]]*\\]).)*</td>)(?:(?!</?td\\b).)*</td>";
Matcher m=Pattern.compile(regex).matcher(b);
while(m.find())
{
System.out.println(m.group());
}
import java.util.regex.*;
public class Test48
{
public static void main(String... args) {
String b = " <td width=\"200\">[a] </td> <td>b </td><td>b </td><td>b </td> <td>[c] </td>";
//System.out.println(b.replace("(?<!\\[)b (?!\\])",""));
Pattern p = Pattern.compile("(<td\\s?[^\\s]*?>\\[.*?\\]\\s*</td>)");
Matcher m = p.matcher(b);
while(m.find()) {
System.out.println(m.group(0));
}
}
}
Matcher m=Pattern.compile("(?s)<td[^>]*?>[^\\[<>]*?\\[+.*?\\].*?</td>").matcher(" <td width=\"200\">[a] </td> <td>b </td> <td>[c] </td>");
while(m.find())
System.out.println(m.group());