Using Perl style regexp, is it possible to look for something not of certain pattern?
For example, [^abc] looks for a SINGLE CHARACTER not a nor b nor c.
But can I specify something longer than a single character?
For example, in the following string, I want to search for the first word which is not a top level domain name and contains no uppercase letter, or perhaps some more complicated rules like having 3-10 characters. In my example, this should be "abcd":
net com org edu ABCE abcdefghijklmnoparacbasd abcd
You can do it using negative look-ahead assertions as:
See it
Explanation:
So the part
(?!(?:net|com|org|edu)$)ensures that input is not one of the top level domains.The part
(?!.*[A-Z])ensures that the input does not have a upper case letter.The part
[a-z]{3,10}$ensures that the input is of length atleast 3 and atmost 10.