In the regular expression, does s include carriage return?

Source: Internet
Author: User
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.

  1. A

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.