What do you mean by the regular expression of this sentence?

Source: Internet
Author: User
Tags perl regular expression
preg_match('/^[a-zA-Z0-9_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/', $username)

Look at the code above, who can explain. Better be more detailed. Thank you.

Reply content:

preg_match('/^[a-zA-Z0-9_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/', $username)

Look at the code above, who can explain. Better be more detailed. Thank you.

all characters in letters or numbers or under line or Han are required to be two or more.

/^[a-zA-Z0-9_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]+$/

^Match the start
$Match end

[a-zA-Z0-9_]Match a number, size, and letter, and write down the line.
[\x7f-\xff]Match a code in the area of the character

Can actually be written as/^[a-zA-Z0-9_\x80-\xff]{2,}$/

{2,}Represents two or more characters to match

Because the first place in the Han word is 1 , the whole word Fu Daisi 127 , is not included \x7f , so can be \x7f changed to \x80 (should).

P.S.: preg Yes perl regular expression , it's an acronym.

In addition, in order to make sure that the Chinese language must be matched, the correct match must be Chinese. It can also be a number of codes (such as odd numbers ...). ) What the.

So it's better to have /^(?:[a-zA-Z0-9_]|[\x80-\xff]{2})+$/ some insurance. As for the Japanese language, what is the language of the software?

And don't know why, JS to use [^\x00-\xff] instead of [\x80-\xff] , it may be to the multi-word character support of the difference bar.

Supplemental: A string in "js is a set of immutable ordered sequences of 16-bit values, each of which is usually derived from the Unicode character set. "So JS's regex can directly match the double-character.

Letters or numbers or underscores or characters of Chinese characters, need more than two

  • 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.