Check string for all lowercase letters in powershell

I want to check if a powershell string is lowercase.

I am not the best regex monkey in the world, but I tried these lines:

if( $mystring -match "[a-z]^[A-Z]" ) {
echo "its lower!"
}

But, of course, they do not work, and the search in interwebs did not force me anywhere. Does anyone know a way to do this (besides testing each character in a loop)?

+5
source share
3 answers

PowerShell does not case-sensitive by default, so you need to use the operator -cmatch:

if ($mystring -cmatch "^[a-z]*$") { ... }

-cmatchalways case sensitive, and -imatchalways case insensitive.

: . , ,

PS: , , , , , , , , , , :

if ($mystring -cmatch "^[^A-Z]*$") { ... }

^ , , . , , -. , -cmatch - .

+9

, , , :

$mystring -ceq $mystring.ToLower()
+5

, , : "^[^A-Z]*$"

false , , . , "hello world 123" .

, .., .

0

All Articles