Determine if string is all caps with regular expression

前端 未结 9 871
轻奢々
轻奢々 2020-12-30 00:46

How can you determine if a string is all caps with a regular expression. It can include punctuation and numbers, just no lower case letters.

相关标签:
9条回答
  • 2020-12-30 00:58

    Why not just use if(string.toUpperCase() == string)? ._. Its more "elegant"...
    I think you're trying to force in RegExp, but as someone else stated, I don't think this is the best use of regexp...

    0 讨论(0)
  • 2020-12-30 00:58

    Simplest would seem to be:

    ^[^a-z]*$
    
    0 讨论(0)
  • 2020-12-30 00:59

    How about (s == uppercase(s)) --> string is all caps?

    0 讨论(0)
  • 2020-12-30 01:00

    The string contains a lowercase letter if the expression /[a-z]/ returns true, so simply perform this check, if it's false you have no lowercase letters.

    0 讨论(0)
  • 2020-12-30 01:06

    That sounds like you want: ^[^a-z]*$

    0 讨论(0)
  • 2020-12-30 01:11
    m/^[^a-z]*$/
    

    For non-English characters,

    m/^\P{Ll}*$/
    

    (\P{Ll} is the same as [^\p{Ll}], which accepts all characters except the ones marked as lower-case.)

    0 讨论(0)
提交回复
热议问题