replaceAll("(?is)<.*?>", "")我不太明白(?is)中的s是什么意思!i我知道是忽略大小写

解决方案 »

  1.   

    ?这样的用法好像跟是否贪婪匹配有关,跟下面的例子有点像,不过正则不太精,
    import java.util.regex.Matcher;
    import java.util.regex.Pattern;public class Test {
    public static void main(String[] args) {
    String str = "<biao><>c<b>";
    Pattern pattern;
    Matcher matcher;

    // 贪婪: 最长匹配 .* : 输出: <biao><>c<b>
    pattern = Pattern.compile("<.*>");
    matcher = pattern.matcher(str);
    while (matcher.find()) {
    System.out.println(matcher.group());
    }

    // 不知是否非贪婪 .*? : 输出: <biao>, <>, <b>
    pattern = Pattern.compile("<.*?>");
    matcher = pattern.matcher(str);
    while (matcher.find()) {
    System.out.println(matcher.group());
    }

    // 使用组, 输出<>里的内容, 输出: 'biao', ' ', 'b'
    // 0组代表整个表达式, 子组从1开始
    pattern = Pattern.compile("<(.*?)>");
    matcher = pattern.matcher(str);
    while (matcher.find()) {
    System.out.println(matcher.group(1));
    }
    }
    }
      

  2.   

    DOTALLpublic static final int DOTALL    Enables dotall mode.    In dotall mode, the expression . matches any character, including a line terminator. By default this expression does not match line terminators.    Dotall mode can also be enabled via the embedded flag expression (?s). (The s is a mnemonic for "single-line" mode, which is what this is called in Perl.) 
      

  3.   

    replaceAll("(?i)<.*?>", "")   : a<中国>b                ->   ab
    replaceAll("(?s)<.*?>", "")   : a<C\r\nN>b           ->   ab
    replaceAll("(?is)<.*?>", "")  : a<中\r\n国>b         ->   ab