Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    the Netherlands
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need help on Pattern Matching

    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

  • #2
    New Coder
    Join Date
    Aug 2002
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    $version_short =~ tr/\.//s;

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    the Netherlands
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, and how should I use that?
    I've tried a couple of things, but nothing seems to do what I want

    Mzzl, Chris

  • #4
    New Coder
    Join Date
    Aug 2002
    Posts
    24
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    the Netherlands
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #6
    New Coder
    Join Date
    Aug 2002
    Location
    Moscow, RU
    Posts
    23
    Thanks
    0
    Thanked 1 Time in 1 Post
    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

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    the Netherlands
    Posts
    215
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a lot

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

    Mzzl, Chris


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •