JDE876
JDE876

Reputation: 407

Is there a way to make Perl regex searches case-insensitive?

Example:

my $cities = qr/San Francisco|Los Angeles/;

The scalar $cities will match San Francisco and Los Angeles but will not match SAN FRANCISCO, LOS ANGELES, san francisco, or los angeles. Is there a way to make these variables case insensitive without having to create a capitalized version of them?

Upvotes: 3

Views: 2947

Answers (2)

Andy Lester
Andy Lester

Reputation: 93666

It's not that you want to make the scalar $cities case-insensitive, but the regular expression it is referencing. Use the /i modifier.

my $cities = qr/San Fransisco|Los Angeles/i;

You may find it useful to read the Perl regular expression tutorial: perldoc perlretut.

Upvotes: 8

OrangeDog
OrangeDog

Reputation: 38777

my $cities = qr/San Fransisco|Los Angeles/i;

Perl regular expression modifiers

Upvotes: 10

Related Questions