Go backward to Regexp Operators.
Go up to Regexp.
Case-sensitivity in Matching
----------------------------
Case is normally significant in regular expressions, both when
matching ordinary characters (i.e., not metacharacters), and inside
character sets. Thus a `w' in a regular expression matches only a
lower case `w' and not an upper case `W'.
The simplest way to do a case-independent match is to use a character
set: `[Ww]'. However, this can be cumbersome if you need to use it
often; and it can make the regular expressions harder for humans to
read. There are two other alternatives that you might prefer.
One way to do a case-insensitive match at a particular point in the
program is to convert the data to a single case, using the `tolower' or
`toupper' built-in string functions (which we haven't discussed yet;
see Built-in Functions for String Manipulation: String Functions.).
For example:
tolower($1) ~ /foo/ { ... }
converts the first field to lower case before matching against it.
Another method is to set the variable `IGNORECASE' to a nonzero
value (see Built-in Variables.). When `IGNORECASE' is not zero,
*all* regexp operations ignore case. Changing the value of
`IGNORECASE' dynamically controls the case sensitivity of your program
as it runs. Case is significant by default because `IGNORECASE' (like
most variables) is initialized to zero.
x = "aB"
if (x ~ /ab/) ... # this test will fail
IGNORECASE = 1
if (x ~ /ab/) ... # now it will succeed
In general, you cannot use `IGNORECASE' to make certain rules
case-insensitive and other rules case-sensitive, because there is no way
to set `IGNORECASE' just for the pattern of a particular rule. To do
this, you must use character sets or `tolower'. However, one thing you
can do only with `IGNORECASE' is turn case-sensitivity on or off
dynamically for all the rules at once.
`IGNORECASE' can be set on the command line, or in a `BEGIN' rule.
Setting `IGNORECASE' from the command line is a way to make a program
case-insensitive without having to edit it.
The value of `IGNORECASE' has no effect if `gawk' is in
compatibility mode (see Invoking `awk': Command Line.). Case is
always significant in compatibility mode.