How to check whether a variable contains consecutive letters, all uppercase letters or all lowercase letters?
Source: Internet
Author: User
How to check whether a variable contains consecutive letters, all uppercase letters or all lowercase letters $ str = & quot; ads sends a lsd to lose weight at home and falls in love with sdafgdsfghfdghjgfjghjgfhj Fang Saada waste Shita. by law 48955235 Sada waste where local teachers will immediately learn & quot; $ p = & quot; /\ d {5}/I & qu how to query a variable containing consecutive letters, all uppercase letters or all lowercase letters
$ Str = "ads sends a lsd to lose weight at home and falls in love with sdafgdsfghfdghjgfjghjgfhj Fang Saada, waste of Shi Dafu, and get to know about it immediately after being wasted by law 48955235 Sada ";
$ P = "/\ d {5}/I ";
Preg_match_all ($ p, $ str, $ result );
Var_dump ($ result );
The above five consecutive numbers can be found. if you change the number to a letter, how do you write the regular expression? check whether the number of digits in the letter (all in lower case or all in upper case) is unlimited.
------ Solution --------------------
/[A-z] | [A-Z] + // or [a-z]/I
------ Solution --------------------
Correct:/[a-z] +/I
The above is case insensitive.
/[A-z] +/
------ Solution --------------------
$ P = "/[a-z] {5,}/I ";
------ Solution --------------------
Wrong. Try this way.
$ P = "/[a-z] {5,} | [A-Z] {5 ,}/";
------ Solution --------------------
What does the author mean by "no limit on the number of digits"? it can be 0, that is:/[a-z] */
------ Solution --------------------
All in upper or lower case is:/([a-z] *) | ([A-Z] *)/
------ Solution --------------------
There is no limit to the number of digits in the query (all in lower case or all in upper case)
All in lower case/[a-z] +/
All uppercase/[A-Z] +/
No, it must be wrong, so it cannot be *
------ Solution --------------------
$ P = "/[A-z] + /";
Uppercase and lowercase letters for A-z matching
+ Appearance times greater than or equal to 1
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