I have to do a regular expression in PHP which catch in a text the strings that contain only uppercase letters, digits, or underscore. Exemple : THIS_STUFF
, THIS_2_STUFF
, ONE_MORE_STUFF_2_CATCH
etc...
It works well with : /[A-Z0-9_]/
BUT, I want to catch the sequences that are only :
- minimum 5 chars ==> /[A-Z0-9_]{5,}/
- AND containing min 3 uppercase letters ==> ????
Have you any ideas ?
Thanks !
AND containing min 3 uppercase letters ==> ????
Use a positive lookahead assertion at the start for this.
^(?=(?:[^A-Z\n]*[A-Z]){3})[A-Z0-9_]{5,}$
OR
\b(?=(?:[^A-Z]*[A-Z]){3})[A-Z0-9_]{5,}+\b
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.