go to previous page   go to home page   go to next page

Answer:

Use [A-Za-z] to include only alphabetic characters.

The expression [a-zA-Z] also works.


Basic Regular Expressions: Exclusions

Regular Expression
(Delimit with quotes)
String
(Delimit with quotes)

Rule 4.  Exclusions

To match any character except a list of excluded characters, put the excluded charaters between [^ and ]. The caret ^ must immediately follow the [ or else it stands for just itself.

Regular ExpressionMatches
[^a] any character except 'a'
[^aA] any character except 'a' or 'A'
[^a-z] any character except a lower case character
[^.] any character not a period
a^z a^z
[a^z] a or ^ or z

The character '.' (period) is a metacharacter (it sometimes has a special meaning). But inside of brackets it does not have a special meaning. It stand for just itself. (Most metacharacters, when used inside of brackets, stand for just themselves.)

Bug Alert! The regular expression [^Z]  matches all characters other than capital 'Z'. This includes lower case characters, digits, spaces, ..., everything but 'Z'. (The bug is to mistakenly assume that [^Z] matches only uppercase 'A' through 'Y'. If this is what you want, use [A-Y] ).


QUESTION 12:

Does [^aeiou][aeiou][^aeiou] match bat?