You can easily search for all characters except those in square brackets by
putting a caret (^
) as the first character
after the left square bracket ([
). To match
all characters except lowercase vowels, use [^aeiou]
.
Like the anchors in places that can't be considered an anchor, the right
square bracket (]
) and dash (-
) do not have a special meaning if they directly
follow a [
. Table 32-2 has some examples.
Table 32-2. Regular expression character set examples
Regular expression |
Matches |
---|---|
|
Any digit |
|
Any character other than a digit |
|
Any digit or a |
|
Any digit or a |
|
Any character except a digit or a |
|
Any digit or a |
|
Any digit followed by a |
|
Any digit or any character between 9 and z |
|
Any digit, a |
Many languages have adopted the
Perl regular expression syntax for ranges;
for example, \w
is equivalent to "any word character"
or [A-Za-z0-9_]
, while \W
matches anything
but a word character. See the
perlre(1) manual page for more details.
— BB