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

Discussion in 'Perl Misc' started by Merlin, Jan 31, 2004.

  1. Merlin

    Merlin Guest

    ($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"
    Merlin, Jan 31, 2004
    #1
    1. Advertising

  2. 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$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval
    Tassilo v. Parseval, Jan 31, 2004
    #2
    1. Advertising

  3. Merlin

    gnari Guest

    "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
    gnari, Jan 31, 2004
    #3
  4. 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)
    Jeff 'japhy' Pinyan, Jan 31, 2004
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hiwa
    Replies:
    0
    Views:
    631
  2. Merrigan
    Replies:
    4
    Views:
    558
    Chris
    Dec 14, 2007
  3. Replies:
    9
    Views:
    374
    Paul McGuire
    Sep 7, 2009
  4. Venugopal
    Replies:
    11
    Views:
    1,500
    Tassilo v. Parseval
    Nov 5, 2003
  5. Gancy
    Replies:
    4
    Views:
    167
    Rasto Levrinc
    Feb 3, 2005
Loading...

Share This Page