比如这个字符串"qweasdzxc"
我只想取出"qwe"和"zxc",这个正则如何写?谢谢!
[code="java"]
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Main {
/**
* @param args
*/
public static void main(String[] args) {
String str = "<script>qwe</script>asd<script>zxc</script>";
Pattern pattern = Pattern.compile("<script>([^<>]*)</script>");
Matcher matcher = pattern.matcher(str);
while(matcher.find()){
System.out.println(matcher.group(1));
}
}
}
[/code]
[code="java"]@Test
public void testRegx7() {
String source = "<script>qwe</script>asd<script>zxc</script>";
Pattern pattern = Pattern.compile("<script>(.*?)</script>");
Matcher matcher = pattern.matcher(source);
System.out.println("取得内容:");
while(matcher.find()){
System.out.println("找到:"+matcher.group(1));
}
}[/code]
[b]
[color=blue]这里我将结果直接输出了,你可以对结果进行需要的处理。[/color][/b]