How to implement this simple function involving regular expressions

Source: Internet
Author: User
How to implement this simple function involving regular expressions? Judge a string (which can only contain the following three characters) with 1.26 English letters 2. "0, 1, 2, 3, 4, 5, 6, 7, 8, 9" 10 digits 3. "-" (a hyphen in English), $ str = & quot;/[^ 0-9a-zA-Z]/I & quot;, how do I implement the simple function of regular expressions in hierarchies?
Judge a string (this string can only contain the following three characters)
1. 26 English letters
2. "," 10 digits
3. "-" (a hyphen in English)

------ Solution --------------------
$ Str = "/[^ 0-9a-zA-Z]/I ";
------ Solution --------------------
Khan Lou lied and dropped "-".
$ Str = "/[^ 0-9a-zA-Z _]/I ";
------ Solution --------------------
Upstairs is wrong.
If it is determined that the object does not exist, '-' is not counted?

Why do I need a-zA-Z when I modify it?

/^ [A-z0-9-] + $/I
------ Solution --------------------
PHP code
Preg_match ('/[-a-z0-9] +/I', $ str); // $ str is the string you want to match
------ Solution --------------------
PHP code
    
------ Solution --------------------
Discussion
PHP code
Preg_match ('/[-a-z0-9] +/I', $ str); // $ str is the string you want to match

------ Solution --------------------
Discussion

Reference:

PHP code
$ Str = "jsd-fowfmf564c-s1f23 ";
$ Pattern = '/^ [a-z0-9-] + $/I'; // use the upstairs
Preg_match ($ pattern, $ str, $ result );
If ($ result)
{
Echo "match ";
};
?>
How to implement it using js?

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.