import java.util.regex.*; public class Test1 { public static void main(String[] args) { String b = " <td>[a] </td> <td>[b] </td> <td>[c] </td>"; String regex="(?<=\\[)\\w*(?=\\])"; Matcher m=Pattern.compile(regex).matcher(b); while(m.find()){ System.out.println(m.group());
} } } 测试结果 a b c
String regex = "(?:\\[(.*?)\\])";
package javaTest;import java.util.regex.*; public class Sample { public static void main(String args[]) { String b = " <td>[a] </td> <td>[b] </td> <td>[c] </td>"; String regex="\\[(.*?)\\]"; Matcher m=Pattern.compile(regex).matcher(b); while(m.find()){ System.out.println(m.group(1)); } } } 测试结果: a b c
package javaTest;import java.util.regex.*; public class Sample { public static void main(String args[]) { String b = " <td>[a] </td> <td>[b] </td> <td>[c] </td>"; String regex="\\[(.*?)\\]"; Matcher m=Pattern.compile(regex).matcher(b); while(m.find()){ System.out.println(m.group(1)); } } } 测试结果: a b c
public class Test { public static void main(String[] args) { String str = "<td>[a]</td><td>[b]</td><td>[c]</td>"; String a=str.replaceAll("(<td>)|(</td>)|\\[|\\]",""); System.out.println(a); } }result:abc
public class Test1
{
public static void main(String[] args)
{
String b = " <td>[a] </td> <td>[b] </td> <td>[c] </td>";
String regex="(?<=\\[)\\w*(?=\\])";
Matcher m=Pattern.compile(regex).matcher(b);
while(m.find()){
System.out.println(m.group());
}
}
}
测试结果
a
b
c
public class Sample
{
public static void main(String args[])
{
String b = " <td>[a] </td> <td>[b] </td> <td>[c] </td>";
String regex="\\[(.*?)\\]";
Matcher m=Pattern.compile(regex).matcher(b);
while(m.find()){
System.out.println(m.group(1));
}
}
}
测试结果:
a
b
c
public class Sample
{
public static void main(String args[])
{
String b = " <td>[a] </td> <td>[b] </td> <td>[c] </td>";
String regex="\\[(.*?)\\]";
Matcher m=Pattern.compile(regex).matcher(b);
while(m.find()){
System.out.println(m.group(1));
}
}
}
测试结果:
a
b
c
public class Test {
public static void main(String[] args) {
String str = "<td>[a]</td><td>[b]</td><td>[c]</td>";
String a=str.replaceAll("(<td>)|(</td>)|\\[|\\]","");
System.out.println(a);
}
}result:abc