⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e444. matching across line boundaries in a regular expression.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
By default, the any-character matcher (.) does not match line termination characters such as \n and \r. To allow dot (.) to match line termination characters, the pattern should be compiled with the dotall flag enabled. 
It is also possible to enable dotall mode within a pattern using the inline modifier (?s). For example, dotall mode is enabled in the pattern (?s)a.*b. Dotall mode can be disabled using (?-s). 

    CharSequence inputStr = "abc\ndef";
    String patternStr = ".*c.+d.*";
    
    // Compile with dotall enabled
    Pattern pattern = Pattern.compile(patternStr, Pattern.DOTALL);
    Matcher matcher = pattern.matcher(inputStr);
    boolean matchFound = matcher.matches();    // true
    
    // Use an inline modifier to enable dotall mode
    matchFound = pattern.matches(".*c.+d.*", "abc\r\ndef");     // false
    matchFound = pattern.matches("(?s).*c.+d.*", "abc\r\ndef"); // true

 Related Examples 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -