Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Regular Expressions need help with ':' 's

Dark_RainDark_Rain Posts: 35Member
I am trying to use regular expressions to remove the information from a line read in from a text file, but keep hitting a problem when i hit the string 00:00:04.

The compleate line is eg:

root 1 0 0 Feb17 ? 00:00:04 init [5]
I just want the parts "root 1 init"

So i use the line
[code]
$line =~/^s*(w+)s*(d+)s*d*s*d*s*w+s*d+s* this is where the problem starts next part of line is 00:00:04

[/code]

Can anyone fix this for me or show me how to get round the ':' problem

Thanks

Comments

  • JonathanJonathan Posts: 2,914Member
    : I am trying to use regular expressions to remove the information from a line read in from a text file, but keep hitting a problem when i hit the string 00:00:04.
    :
    : The compleate line is eg:
    :
    : root 1 0 0 Feb17 ? 00:00:04 init [5]
    : I just want the parts "root 1 init"
    :
    : So i use the line
    : [code]
    : $line =~/^s*(w+)s*(d+)s*d*s*d*s*w+s*d+s* this is where the problem starts next part of line is 00:00:04
    :
    : [/code]
    :
    : Can anyone fix this for me or show me how to get round the ':' problem
    :
    I think you might be better off using split here.

    @parts = split(/s+/, $line);
    $output = "$parts[0] $parts[1] $parts[7]";

    What were you trying - you can certainly use colons in regexes...

    $test = '12:00:21';
    $test =~ /^(d+):(d+):(d+)/;
    print "$3:$2:$1"; #prints 21:00:12

    Jonathan

    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • Dark_RainDark_Rain Posts: 35Member
    Jonathan thanks for your help that solved my problem. I went with the split option in the end as it worked better.

    Once again thankyou.

    DR

  • JonathanJonathan Posts: 2,914Member
    : Jonathan thanks for your help that solved my problem. I went with
    : the split option in the end as it worked better.
    :
    You're welcome. And yes, pattern matching may be cool and very powerful, but it isn't always the best solution. :-)

    Jonathan


    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Sign In or Register to comment.