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?