Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Regex exp again... need to match exactly two letters.

Reply
Thread Tools

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

 
 
Merlin
Guest
Posts: n/a
 
      01-31-2004


($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


--
---
The Mission of Our Lady of Fatima.
http://www.the-mission-of-our-lady-of-fatima.org
"I come from Heaven. I am the Lady of The Rosary"



 
Reply With Quote
 
 
 
 
Tassilo v. Parseval
Guest
Posts: n/a
 
      01-31-2004
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
--
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus}) !JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexi ixesixeseg;y~\n~~dddd;eval
 
Reply With Quote
 
 
 
 
gnari
Guest
Posts: n/a
 
      01-31-2004
"Merlin" <The Mission of @ Our Lady of Fatima> wrote in message
news:...
>
>
> ($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




 
Reply With Quote
 
Jeff 'japhy' Pinyan
Guest
Posts: n/a
 
      01-31-2004
On Sat, 31 Jan 2004, it was written:

>($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?

--
Jeff Pinyan RPI Acacia Brother #734 2003 Rush Chairman
"And I vos head of Gestapo for ten | Michael Palin (as Heinrich Bimmler)
years. Ah! Five years! Nein! No! | in: The North Minehead Bye-Election
Oh. Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Something confusing about non-greedy reg exp match gburdell1@gmail.com Python 9 09-07-2009 02:00 PM
search reg-exp for exact match John Butler Ruby 2 11-22-2008 10:52 AM
Multiple Match of regular exp... stratus Perl Misc 5 05-06-2005 08:57 AM
Regex to match say char 't' exactly once in a string and no more than once Gancy Perl Misc 4 02-03-2005 02:05 PM
Java regex can't match lengthy match? hiwa Java 0 01-29-2004 10:09 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57