PDA

View Full Version : Need help on Pattern Matching



chrisvmarle
08-14-2002, 04:11 PM
Hi all,

Hopefully you can help me out.

I'll get to the point, right away:

What I get:
$msg = "version: 1.2.3.4";

What I want:
$msg = "version: 1.2.3.4";
$version = "1.2.3.4";
$version_short = "1.234";

Nothing has changed for $msg.
In $version I want the version number.
In $version_short I want all, but the first dots removed.

Thanks in advance.

Mzzl, Chris

pager
08-15-2002, 01:57 AM
$version_short =~ tr/\.//s;

chrisvmarle
08-15-2002, 10:28 AM
Ok, and how should I use that?
I've tried a couple of things, but nothing seems to do what I want :(

Mzzl, Chris

pager
08-16-2002, 09:46 AM
You're right...

Now I'm po'd.... I shouldn't have told you that - sorry was in the middle of a big project and just couldn't resist the chance to solve it as regex's get my goat big time.. and I got ahead of myself. I'll see what i can do to figure it out today.

There's an easy way to do this but it's too lengthy and that's why the challenge of regex's is so intriguing to me. Zap the whole thing in a single short line.

chrisvmarle
08-16-2002, 10:04 AM
Zap the whole thing in a single short line.

That's what I'm looking for.
I used to use this:
$version = $msg;
$version =~ s/^version: //;
$version_short = $version;
$version_short =~ s/\./,/;
$version_short =~ s/\.//g;

But 1st, this is wat too much code and 2nd after the first digit it's a "," not a "." :(

I hope you can help me. Thanks for taking time for it :)

Mzzl, Chris

Inci
08-30-2002, 08:40 PM
Hello

there we go:

$msg = "version: 1.2.3.4";
$version = $msg;

#removing a 'version:(and maybe one space )'

$version =~ s/version\:(?:\s)?((\d+)((?:\.\d)+))/$1/i;

#combining it
$version_short = $2 . ',' . $3;

#deleting dots (.)
$version_short =~ s/\.//g;

thats it

chrisvmarle
08-30-2002, 10:35 PM
Thanks a lot :)

I'll try it soon, because I'm quiet in a hurry right now ;)

Mzzl, Chris