Perl

Moderators: Jonathan
Number of threads: 1236
Number of posts: 3605

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Regular Expressions need help with ':' 's Posted by Dark_Rain on 19 Feb 2004 at 1:19 PM
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
$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



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

Thanks
Report
Re: Regular Expressions need help with ':' 's Posted by Jonathan on 19 Feb 2004 at 1:48 PM
: 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
:
: $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
: 
: 

:
: 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.");

Report
Re: Regular Expressions need help with ':' 's Posted by Dark_Rain on 19 Feb 2004 at 2:48 PM
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

Report
Re: Regular Expressions need help with ':' 's Posted by Jonathan on 19 Feb 2004 at 3:12 PM
: 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.");




 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.