Solution for extracting a certain Chinese character from a Chinese character string using regular expressions

Source: Internet
Author: User
The regular expression is used to extract a Chinese character from a Chinese character string. & lt ;? Phpheader (Content-type: & nbsp; texthtml; & nbsp; charsetgb2312); & nbsp; $ regex & nbsp; large (xhh {1}); & nbsp; & nbsp; how to write here? I don't know how to use regular expressions. I hope you can help me solve this problem. thank you $ str & regular expressions for retrieving a certain Chinese character from a Chinese character string.
 Header ("Content-type: text/html; charset = gb2312 ");
$ Regex = '/large (\ xhh {1}) good/'; // How to write here? I don't know regular expressions. I hope you can help me solve this problem. thank you.
$ Str = 'Hello all ';
$ Matches = array ();

If (preg_match ($ regex, $ str, $ matches )){
Var_dump ($ matches );
}
?>


I want to extract the word "home"
------ Solution --------------------
Reference:
Garbled characters. $ Str = 'A hello everyone '; $ regex ='/(.*?) Good /';


Header ("Content-type: text/html; charset = gb2312 ");
$ Regex = '/large (.*?) Good /';
$ Str = 'Hello all ';
$ Str = mb_convert_encoding ($ str, 'gb2312', 'utf-8 ');
$ Regex = mb_convert_encoding ($ regex, 'gb2312', 'utf-8 ');;
$ Matches = array ();

If (preg_match ($ regex, $ str, $ matches )){
Var_dump ($ matches );
// Array (2) {[0] => string (12) "" [1] => string (3) ""}
}

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.