Matching a part of a string

Discussion in 'Perl Misc' started by TonyShirt, Jul 1, 2004.

  1. TonyShirt

    TonyShirt Guest

    I have a string "FILEVERSION 1,01,0,21\n"
    I want to match only the numbers "1,01,0,21"

    i'm using /([0-9]+,[0-9]+,[0-9]+,[0-9]+)/
    but I'm still getting the whole string. Why? I know its easier (At
    this point) to just split the string by \s, but I just cant give it
    up!
     
    TonyShirt, Jul 1, 2004
    #1
    1. Advertising

  2. TonyShirt wrote:
    > I have a string "FILEVERSION 1,01,0,21\n"
    > I want to match only the numbers "1,01,0,21"
    >
    > i'm using /([0-9]+,[0-9]+,[0-9]+,[0-9]+)/
    > but I'm still getting the whole string. Why?


    Since we are not mind readers in this group, you need to post a short
    but complete program that illustrates the problem. If you do, somebody
    can point out what it is you are doing wrong.

    --
    Gunnar Hjalmarsson
    Email: http://www.gunnar.cc/cgi-bin/contact.pl
     
    Gunnar Hjalmarsson, Jul 1, 2004
    #2
    1. Advertising

  3. TonyShirt

    gnari Guest

    "TonyShirt" <> wrote in message
    news:...
    > I have a string "FILEVERSION 1,01,0,21\n"
    > I want to match only the numbers "1,01,0,21"
    >
    > i'm using /([0-9]+,[0-9]+,[0-9]+,[0-9]+)/
    > but I'm still getting the whole string. Why? I know its easier (At
    > this point) to just split the string by \s, but I just cant give it
    > up!


    there probably is somemthing wrong with how you are 'getting' it

    my $x="FILEVERSION 1,01,0,21\n";
    print "gotit: ($1)\n" if $x=~/([0-9]+,[0-9]+,[0-9]+,[0-9]+)/;

    gnari
     
    gnari, Jul 2, 2004
    #3
  4. TonyShirt

    TonyShirt Guest

    "gnari" <> wrote in message news:<cc258o$gsp$>...
    > "TonyShirt" <> wrote in message
    > news:...
    > > I have a string "FILEVERSION 1,01,0,21\n"
    > > I want to match only the numbers "1,01,0,21"
    > >
    > > i'm using /([0-9]+,[0-9]+,[0-9]+,[0-9]+)/
    > > but I'm still getting the whole string. Why? I know its easier (At
    > > this point) to just split the string by \s, but I just cant give it
    > > up!

    >
    > there probably is somemthing wrong with how you are 'getting' it
    >
    > my $x="FILEVERSION 1,01,0,21\n";
    > print "gotit: ($1)\n" if $x=~/([0-9]+,[0-9]+,[0-9]+,[0-9]+)/;
    >
    > gnari


    This makes sense -- I was struggling becuse I thought that $x contain the match.
    Thanks for the help! Tony
     
    TonyShirt, Jul 2, 2004
    #4
  5. TonyShirt

    John Bokma Guest

    Purl Gurl wrote:

    > TonyShirt wrote:
    >
    > (snipped)
    >
    >>I have a string "FILEVERSION 1,01,0,21\n"
    >>I want to match only the numbers "1,01,0,21"

    >
    >
    > $string = "FILEVERSION 1,01,0,21\n";
    >
    > chomp ($string =~ tr/A-Z //d);
    >
    > print $string;


    I personally don't like it when values in variables morph into a
    different meaning. Also, FILEVERSION 1,01,0,21,Alpha...

    --
    John MexIT: http://johnbokma.com/mexit/
    personal page: http://johnbokma.com/
    Experienced Perl programmer available: http://castleamber.com/
    Happy Customers: http://castleamber.com/testimonials.html
     
    John Bokma, Jul 2, 2004
    #5
    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. =?Utf-8?B?Sm9l?=

    matching on part of node's attribute

    =?Utf-8?B?Sm9l?=, Feb 2, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    392
    =?Utf-8?B?Sm9l?=
    Feb 3, 2006
  2. =?ISO-8859-1?Q?Martin_J=F8rgensen?=
    Replies:
    5
    Views:
    1,306
    =?ISO-8859-1?Q?Martin_J=F8rgensen?=
    May 6, 2006
  3. Marc Bissonnette

    Pattern matching : not matching problem

    Marc Bissonnette, Jan 8, 2004, in forum: Perl Misc
    Replies:
    9
    Views:
    238
    Marc Bissonnette
    Jan 13, 2004
  4. BerNaC
    Replies:
    9
    Views:
    146
    colin_lyse
    Feb 16, 2005
  5. Bobby Chamness
    Replies:
    2
    Views:
    235
    Xicheng Jia
    May 3, 2007
Loading...

Share This Page