Regex exp again... need to match exactly two letters.

M

Merlin

($row[0] =~ /^[A-Z]{2}$/)

Shouldn't this match a line that has ONLY the country code on it, ie;

AU
US
Fred's AUSTRALIA
Bills US Postal Service. GA

and I only want it to return line 1 and 2. That is
AU
and
US

So it has to match a line that has ONLY two capital letters in it.

thanks
Robert
 
T

Tassilo v. Parseval

Also sprach Merlin:
($row[0] =~ /^[A-Z]{2}$/)

Shouldn't this match a line that has ONLY the country code on it, ie;

AU
US
Fred's AUSTRALIA
Bills US Postal Service. GA

and I only want it to return line 1 and 2. That is
AU
and
US

So it has to match a line that has ONLY two capital letters in it.

And that's exactly what the pattern '^[A-Z]{2}$' does. Why do you think
it doesn't?

Tassilo
 
G

gnari

Merlin said:
($row[0] =~ /^[A-Z]{2}$/)

Shouldn't this match a line that has ONLY the country code on it, ie;

AU
US
Fred's AUSTRALIA
Bills US Postal Service. GA

and I only want it to return line 1 and 2. That is
AU
and
US

So it has to match a line that has ONLY two capital letters in it.

yes. if it does not work you must examine what $row[0] contains
at the time of the match. maybe you are testing the wrong variable,
or maybe it contains extra stuff like spaces.

gnari
 
J

Jeff 'japhy' Pinyan

($row[0] =~ /^[A-Z]{2}$/)

Shouldn't this match a line that has ONLY the country code on it, ie;

No, it should match a STRING that has ONLY the country code on it, plus an
optional trailing newline.

If your string has multiple lines in it, you'll need to add the /m
modifier.

Now, what are you doing, and what's not working like you'd expect?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top