Reputation: 448
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 !
Upvotes: 0
Views: 101
Reputation: 174696
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
Upvotes: 2