PHPandJAVA {code...} php is null. {code...} java can all be matched. In the document, \ s indicates that blank character carriage return is not a blank character.
The actual test results are different in different environments.
Test File Content
Test.txt
PH
P and JA
VA
$text=file_get_contents('test.txt');#print $text;preg_match("/PH\sP/s",$text,$match);print_r($match);preg_match("/JA\sVA/s",$text,$match);print_r($match);
Php matching is blank
Pattern php = Pattern.compile("PH\\sP",Pattern.DOTALL);Pattern java = Pattern.compile("JA\\sVA",Pattern.DOTALL); BufferedReader in = new BufferedReader(new FileReader("test.txt")); StringBuffer sb=new StringBuffer (); String s; while ((s = in.readLine()) != null) { sb.append(s); }Matcher m = php.matcher(sb);while(m.find()) { System.out.println(m.group());} m = java.matcher(sb);while(m.find()) { System.out.println(m.group());}
Both java
Reply content:
In this document, \ s indicates that blank characters are not counted as blank characters when you press Enter.
The actual test results are different in different environments.
Test File Content
Test.txt
PH
P and JA
VA
$text=file_get_contents('test.txt');#print $text;preg_match("/PH\sP/s",$text,$match);print_r($match);preg_match("/JA\sVA/s",$text,$match);print_r($match);
Php matching is blank
Pattern php = Pattern.compile("PH\\sP",Pattern.DOTALL);Pattern java = Pattern.compile("JA\\sVA",Pattern.DOTALL); BufferedReader in = new BufferedReader(new FileReader("test.txt")); StringBuffer sb=new StringBuffer (); String s; while ((s = in.readLine()) != null) { sb.append(s); }Matcher m = php.matcher(sb);while(m.find()) { System.out.println(m.group());} m = java.matcher(sb);while(m.find()) { System.out.println(m.group());}
Both java
Enter/r/n, not blank. It should be included in/s mode,preg_match('/lalla /s',$youString), The dot metacharacter (.) in s Mode matches all characters, including line breaks
If the modifier s is set"Period"Metacharacters match all characters, including line breaks. If this modifier does not exist, the dot does not match the linefeed. This modifier is equivalent to the/s modifier in perl. An anti-character class such as 1 always matches the line break, and does not rely on the settings of the modifier s.
- A