Velocity Reviews > Perl > Matching a part of a string

# Matching a part of a string

TonyShirt
Guest
Posts: n/a

 07-01-2004
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!

Guest
Posts: n/a

 07-01-2004
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.

--
Email: http://www.gunnar.cc/cgi-bin/contact.pl

gnari
Guest
Posts: n/a

 07-01-2004
"TonyShirt" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) om...
> 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

TonyShirt
Guest
Posts: n/a

 07-02-2004
"gnari" <(E-Mail Removed)> wrote in message news:<cc258o\$gsp\$(E-Mail Removed)>...
> "TonyShirt" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed) om...
> > 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

John Bokma
Guest
Posts: n/a

 07-02-2004
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