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

📄 e443. matching line boundaries in a regular expression.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
By default, the beginning-of-line matcher (^) and end-of-line matcher ($) do not match at line boundaries. They match the beginning and end of the entire input sequence. For example, the pattern ^a matches abc but does not match def\nabc. To enable ^ and $ to match line boundaries, the pattern should be compiled with the multiline flag enabled. 
It is also possible to enable multiline mode within a pattern using the inline modifier (?m). For example, multiline mode is enabled in the pattern (?m)^a. Multiline mode can be disabled using (?-m). 

    CharSequence inputStr = "abc\ndef";
    String patternStr = "abc$";
    
    // Compile with multiline enabled
    Pattern pattern = Pattern.compile(patternStr, Pattern.MULTILINE);
    Matcher matcher = pattern.matcher(inputStr);
    boolean matchFound = matcher.find();    // true
    
    // Use an inline modifier to enable multiline mode
    matchFound = pattern.matches(".*abc$.*", "abc\r\ndef");     // false
    matchFound = pattern.matches("(?m).*abc$.*", "abc\r\ndef"); // true

⌨️ 快捷键说明

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