Examples of negated character classes

The following regex matches any character except a forward slash:

[^/]

Also, remember the fact that a negated character such as [^/] must match a single character. It doesn't match zero-width assertions such as ^, $, , z, , B, and so on.

The following regex matches any character but a and A:

    [^aA]

The following regex matches all the consonants of the English language:

    [^aeiou]

All non-vowels are considered consonants; hence, we just need to negate the vowel character class.

The following regex matches all the characters except digits, dots, and line breaks:

    [^0-9.
]

In this regex, we could also use the predefined property d for [0-9]:

    [^d.
]

This regex matches http followed by any character except s:

    http[^s]
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.221.144