View Full Version : Need help on Pattern Matching

08-14-2002, 05:11 PM
Hi all,

Hopefully you can help me out.

I'll get to the point, right away:

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

What I want:
$msg = "version:";
$version = "";
$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

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

08-15-2002, 11: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

08-16-2002, 10: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.

08-16-2002, 11: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

08-30-2002, 09:40 PM

there we go:

$msg = "version:";
$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

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

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

Mzzl, Chris