[^ A-zA-Z0-9u4e00-u9fa5s] I use this matching symbol. in php, preg_replace always reports an error. how can this problem be solved?

Source: Internet
Author: User
[^ A-zA-Z0-9u4e00-u9fa5s] I use this matching symbol. in php, preg_replace always reports an error. how can this problem be solved? [^ A-zA-Z0-9 \ u4e00-\ u9fa5 \ s] please enlighten me


Reply to discussion (solution)

/[^ A-zA-Z0-9 \ x {4e00}-\ x {9fa5} \ s]/u
It must be UTF-8 encoded.

However, if it is UTF-8 encoded, \ w will be able to match Chinese characters. why bother?

What is the error message?

What is the error message?


I matched all the characters. php pre_place cannot match this regular expression. it is depressing!

Header ('content-type: text/html; charset = utf-8 '); $ s = 'Asa-de + Chinese 123 '; $ p = '/[^ a-zA-Z0-9 \ x {4e00}-\ x {9fa5} \ s]/U'; echo preg_replace ($ p, '', $ s ); // asade Chinese 123 echo preg_replace ('/[^ \ w \ s]/U', '', $ s); // asade Chinese 123

What is the error message?

WARNING: PREG_MATCH_ALL () [FUNCTION.PREG-MATCH-ALL]: compilation failed: pcre does not support \ L, \ L, \ N {NAME}, \ U, OR \ u at offset 15 in c: \ WAMP \ WWW \ INDEX_MULTI.PHP ON

Header ('content-type: text/html; charset = utf-8 '); $ s = 'Asa-de + Chinese 123 '; $ p = '/[^ a-zA-Z0-9 \ x {4e00}-\ x {9fa5} \ s]/U'; echo preg_replace ($ p, '', $ s ); // asade Chinese 123 echo preg_replace ('/[^ \ w \ s]/U', '', $ s); // asade Chinese 123

Although I still don't know where I am wrong, I can use a tool to match it, but your method is successful, there is no error, learn, thank you

So far, php regular expressions do not support \ u4e00.
So you are not wrong.

So far, php regular expressions do not support \ u4e00.
So you are not wrong.

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.