Regular expressions can be put into online testing tools, but they cannot be put into the echo array of files.

Source: Internet
Author: User
Tags expression engine
Regular expressions can be put in the online testing tool, but the echo array in the file won't work. I can match the regular expressions correctly in those regular expression testing tools, why put it in preg_match_all ('/(\ @ [a-z] + \ | [\ u4e00-\ u9fa5] + \ | [A-Z] + \ | [a-z] + \ | [a-z] + \ | [0-9] +) /is ', $ a) is not acceptable? In the test tool, I can select global search. if I do not select the test tool, I cannot. Is this the reason? Isn't preg_match_all a global search?


Reply to discussion (solution)

Several questions
1. preg_match_all (regular, string, result), you only have two parameters above
2. what is the full-width comma in your parameter segmentation?
3. change \ u to \ x

/(\ @ [A-z] + \ | [\ u4e00-\ u9fa5] + \ | [A-Z] + \ | [a-z] + \ | [a-z] + \ | [0-9] +) /is u

You must have a u modifier because you have unicode characters in the rule string.

The correct statement is as follows:
/(\ @ [A-z] + \ | [\ x {4e00}-\ x {9fa5}] + \ | [A-Z] + \ | [a-z] + \ | [a-z] + \ | [0-9] +) /isu

The correct statement is as follows:
/(\ @ [A-z] + \ | [\ x {4e00}-\ x {9fa5}] + \ | [A-Z] + \ | [a-z] + \ | [a-z] + \ | [0-9] +) /isu
Why is the final result $ res (the third parameter) a two-dimensional array with two elements, and the content of the two elements is the same?
$ Res [0] $ res [1] is the same

The correct statement is as follows:
/(\ @ [A-z] + \ | [\ x {4e00}-\ x {9fa5}] + \ | [A-Z] + \ | [a-z] + \ | [a-z] + \ | [0-9] +) /isu
Thanks for the result. I have already asked why I tested the following rule in the online testing tools before to get the correct match. I cannot put it in the file?
@ [A-z] + \ | [\ u4e00-\ u9fa5] + \ | [A-Z] + \ | [a-z] + \ | [a-z] + \ | [0-9] +

This \ u4e00-\ u9fa5 is the Chinese range of unicode encoding. it can be seen that your testing tool is in the form of a webpage
Php's regular expression engine cannot recognize this format, so it naturally cannot get the correct result.


The correct statement is as follows:
/(\ @ [A-z] + \ | [\ x {4e00}-\ x {9fa5}] + \ | [A-Z] + \ | [a-z] + \ | [a-z] + \ | [0-9] +) /isu
Thanks for the result. I have already asked why I tested the following rule in the online testing tools before to get the correct match. I cannot put it in the file?
@ [A-z] + \ | [\ u4e00-\ u9fa5] + \ | [A-Z] + \ | [a-z] + \ | [a-z] + \ | [0-9] +
Online testing or browser plug-ins use a regular expression in the js engine instead of the php engine.

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.