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
:
: 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.");
Once again thankyou.
DR
: 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.");