Click here to get back home

Question on regex

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Question on regex cyrusgreats 03-07-2008
---> Re: Question on regex Gunnar Hjalmars...03-07-2008
Posted by cyrusgreats on March 7, 2008, 4:17 pm
Please log in for more thread options
I'm using the following regex using perl to get anything that is not
0.0 but it doesn't work the way I want it, I need to print those that
are not 0.0

The string is:

0.0 19968 admin /bin/bash -l
1.0 20037 admin /bin/bash -l
0.2 20085 admin /bin/bash -l
0.0 20363 admin /bin/bash -l

next if $line =~ /^\s0.0/; # skip 0.0
print $line, "\n";

the out put is:
next if $line =~ /^\s0.0/; # skip 0.0

But I all I want is:

1.0 20037 admin /bin/bash -l
0.2 20085 admin /bin/bash -l

Anyone out there know how to fix this one?
Thanks in advance..

Posted by Gunnar Hjalmarsson on March 7, 2008, 4:38 pm
Please log in for more thread options
cyrusgreats@gmail.com wrote:
> I'm using the following regex using perl to get anything that is not
> 0.0 but it doesn't work the way I want it, I need to print those that
> are not 0.0
>
> The string is:
>
> 0.0 19968 admin /bin/bash -l
> 1.0 20037 admin /bin/bash -l
> 0.2 20085 admin /bin/bash -l
> 0.0 20363 admin /bin/bash -l
>
> next if $line =~ /^\s0.0/; # skip 0.0
> print $line, "\n";
>
> the out put is:
> next if $line =~ /^\s0.0/; # skip 0.0
>
> But I all I want is:
>
> 1.0 20037 admin /bin/bash -l
> 0.2 20085 admin /bin/bash -l

Please post a short but complete program to show us what you are doing,
as is suggested in the posting guidelines for this group:
http://www.rehabitation.com/clpmisc/clpmisc_guidelines.html

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Posted by cyrusgreats on March 7, 2008, 4:50 pm
Please log in for more thread options
> Please post a short but complete program to show us what you are doing,
> as is suggested in the posting guidelines for this
group:http://www.rehabitation.com/clpmisc/clpmisc_guidelines.html
>
> --
> Gunnar Hjalmarsson
> Email:http://www.gunnar.cc/cgi-bin/contact.pl
Well that depends of the question, the question is very straight
forward, anyway here is portion of the code..again thanks..

my $cmd = "ps -eo pcpu,pid,user,args";
my @output = '$cmd';
foreach my $line (@output) {
next if $line =~ /\s0.0/; # skip 0.0
print $line, "\n";
}


Posted by Willem on March 7, 2008, 5:07 pm
Please log in for more thread options
cyrusgreats@gmail.com wrote:
)> Please post a short but complete program to show us what you are doing,
)> as is suggested in the posting guidelines for this
group:http://www.rehabitation.com/clpmisc/clpmisc_guidelines.html

)>
)> --
)> Gunnar Hjalmarsson
)> Email:http://www.gunnar.cc/cgi-bin/contact.pl
) Well that depends of the question, the question is very straight
) forward, anyway here is portion of the code..again thanks..
)
) my $cmd = "ps -eo pcpu,pid,user,args";
) my @output = '$cmd';
) foreach my $line (@output) {
) next if $line =~ /\s0.0/; # skip 0.0
) print $line, "\n";
) }

First: The dot matches any character in a regexp.
Second: I don't see the caret at the start of the regexp to anchor it.
This will probably result in spurious matches.
Third: The lines will already have newlines on them so the extra one
in the print statement will produce blank lines.

Oh, and fourth: in the original question, I *did* see the caret at the
start, which made the question impossible to answer as such, let alone
straight forward. This is one reason why the best way is to copy-paste
the relevant bits of your code. All characters count.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT

Posted by cyrusgreats on March 7, 2008, 5:19 pm
Please log in for more thread options
> cyrusgre...@gmail.com wrote:
>
> )> Please post a short but complete program to show us what you are doing,
> )> as is suggested in the posting guidelines for this
group:http://www.rehabitation.com/clpmisc/clpmisc_guidelines.html
> )>
> )> --
> )> Gunnar Hjalmarsson
> )> Email:http://www.gunnar.cc/cgi-bin/contact.pl
> ) Well that depends of the question, the question is very straight
> ) forward, anyway here is portion of the code..again thanks..
> )
> ) my $cmd = "ps -eo pcpu,pid,user,args";
> ) my @output = '$cmd';
> ) foreach my $line (@output) {
> ) next if $line =~ /\s0.0/; # skip 0.0
> ) print $line, "\n";
> ) }
>
> First: The dot matches any character in a regexp.
> Second: I don't see the caret at the start of the regexp to anchor it.
> This will probably result in spurious matches.
> Third: The lines will already have newlines on them so the extra one
> in the print statement will produce blank lines.
>
> Oh, and fourth: in the original question, I *did* see the caret at the
> start, which made the question impossible to answer as such, let alone
> straight forward. This is one reason why the best way is to copy-paste
> the relevant bits of your code. All characters count.
>
> SaSW, Willem
> --
> Disclaimer: I am in no way responsible for any of the statements
> made in the above text. For all I know I might be
> drugged or something..
> No I'm not paranoid. You all think I'm paranoid, don't you !
> #EOT

ok, how about this, what if and only if I want to match anything but
not 0.0, since the above doesn't work..if the string as follows, I'm
interested in 0.2 not 0.0.
space 0.0 somewords
space 0.2 somewords

Similar ThreadsPosted
Little question on regex. October 28, 2004, 1:28 pm
Regex question April 18, 2005, 10:50 am
Yet another regex question. April 18, 2005, 11:23 am
a regex question .. April 30, 2005, 6:20 pm
regex question January 6, 2006, 1:36 pm
Regex Question April 3, 2006, 11:02 pm
Regex question April 8, 2006, 6:18 pm
regex question April 13, 2006, 6:46 pm
Regex question October 31, 2006, 10:31 am
regex question December 1, 2006, 12:21 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap