Matching a part of a string

T

TonyShirt

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!
 
G

Gunnar Hjalmarsson

TonyShirt said:
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.
 
G

gnari

TonyShirt said:
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
 
T

TonyShirt

gnari said:
TonyShirt said:
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
 
J

John Bokma

Purl said:
TonyShirt wrote:

(snipped)



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

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top