Regular Expression matching character-PHP source code

Source: Internet
Author: User
Ec (2); regular expression matching rules are modified as follows :([. n] *), of course, if it is written directly in a java program, you need to change it ([. n] *) the result is that the program is run again and NO content can be obtained. I was puzzled, and changed it to the following rules: ([. | n] *) and ([n.] *) the result is still not good, and nothing can be obtained. It seems that the dot and line break are busy ~ Then I checked the Internet. Although I didn't find out what the above rule was, I found a script ec (2); script

Modify the regular expression matching rules as follows:
([. N] *). Of course, if it is written directly in a java program, you need to change it to ([. n] *)
The result is that the program is run again and NO content can be obtained. I was puzzled and changed it to the following rules:
([. | N] *) and ([n.] *)
The result still does not work, and nothing can be obtained. It seems that the dot and line break are busy ~
Then I checked the Internet. Although I didn't find out what the above rule was, I found a solution. After a try, I could indeed match any character including line breaks, the following are the correct Regular Expression matching rules:
([Ss] *)
You can also use "([dd] *)" and "([ww.


In a text file, this expression can match all English letters.
/[-~] /
This expression can match all non-English characters (such as Chinese)
/[^-~] /
/Is Used in vi. You do not need it in editplus or program/


$ Pattern = "/d /";
If (preg_match ($ pattern, $ str, $ output )){
Echo "matched characters". $ output;
}
Else echo "failed to match characters ";
?>

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.