How would I check a string contains at least one lowercase and at least one uppercase using awk
.
My attempt:
^.*[a-z]+[A-Z]+.*$|^.*[A-Z]+[a-z]+.*$
How would I check a string contains at least one lowercase and at least one uppercase using awk
.
My attempt:
^.*[a-z]+[A-Z]+.*$|^.*[A-Z]+[a-z]+.*$
With awk
you can use the logical operator &&
and test for both lowercase and uppercase using their respective character classes:
$ cat file
abc
ABC
aBc
123
$ awk '/[a-z]/&&/[A-Z]/{print $0,"[PASS]";next}{print $0,"[FAIL]"}' file
abc [FAIL]
ABC [FAIL]
aBc [PASS]
123 [FAIL]
Try this. ;)
.*(?=.*[a-z])(?=.*[A-Z]).*
. = multiple times
* = any char
?= = last check should be true
[a-z]/[A-Z] = should contain the range of a-z and A-Z
You can test anytime your regex here: Regex Tester