word boundry

word boundry

am 18.05.2011 09:06:50 von Irfan Sayed

--0-840058961-1305702410=:29923
Content-Type: text/plain; charset=us-ascii

hi,

i need to catch "error" word in log file

i used reg exp like this :

if ($_ =~ /\berror\b/)
is this correct ?

--irfu

--0-840058961-1305702410=:29923--

Re: word boundry

am 18.05.2011 15:06:35 von saran

http://perldoc.perl.org/perlre.html --> Try reading this Assertions
Page


You can also try something like
if(~/\s+error\s+|^error\s+|\s+error$/si)

this means one or more blank spaces
sometimes the error word may be in beginning(^error\s+) or in the end
of line(\s+error$).

~ Saran




On May 18, 12:06=A0pm, irfan_sayed2...@yahoo.com (Irfan Sayed) wrote:
> hi,
>
> i need to catch "error" word in log file
>
> i used reg exp like this :
>
> if ($_ =3D~ /\berror\b/)
> is this correct ?
>
> --irfu


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: word boundry

am 18.05.2011 17:22:47 von Jim Gibson

At 12:06 AM -0700 5/18/11, Irfan Sayed wrote:
>hi,
>
>i need to catch "error" word in log file
>
>i used reg exp like this :
>
>if ($_ =~ /\berror\b/)
>is this correct ?

Yes, that looks correct.


--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/

Re: word boundry

am 18.05.2011 18:49:58 von Uri Guttman

>>>>> "S" == Saran writes:

S> http://perldoc.perl.org/perlre.html --> Try reading this Assertions
S> Page


S> You can also try something like
S> if(~/\s+error\s+|^error\s+|\s+error$/si)

S> this means one or more blank spaces
S> sometimes the error word may be in beginning(^error\s+) or in the end
S> of line(\s+error$).

that is way too complex and also slower. whitespace or beginning or end
of a string next to a word character is also a word boundary.

and your regex doesn't work with '[error]' as it isn't next to white
space or string ends. the word boundary regex works there.

the /s modifier isn't doing anything since you don't have any . in your regex.

also what is the leading ~ doing there?

uri

--
Uri Guttman ------ uri@stemsystems.com -------- http://www.sysarch.com --
----- Perl Code Review , Architecture, Development, Training, Support ------
--------- Gourmet Hot Cocoa Mix ---- http://bestfriendscocoa.com ---------

--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/