correct usage of carets inside negative lookahead expression in perl
I am trying to match any word that is not completely composed of capitals
or lowercase letters, and I have the following regex written:
if ($line =~ /(?!^[A-Z][A-Z]+(\s*)$)(?!^[a-z][a-z]+(\s*)$)/) {
print $line;
}
The expression below should match words with all capital letters
(?!^[A-Z][A-Z]+(\s*)$)
and this should match words with all lowercase letters
(?!^[a-z][a-z]+(\s*)$)
I combine both and try to match this with the following words, ASDSFSDF,
asdfasdfasdf, and asdasdfFFFdsfs. I notice that it is matching everything.
only when i move the caret outside the brackets as in:
^(?![A-Z][A-Z]+(\s*)$)^(?![a-z][a-z]+(\s*)$)/)
do i see that its only maching the asdasdfFFFdsfs. can someone explain to
me why i need to move the operator outside of the negative lookahead
expression? i am new to regexp and i am confused.
Thanks.
No comments:
Post a Comment