Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: search for exact string

by Punitha (Priest)
on Mar 27, 2008 at 12:51 UTC ( #676711=note: print w/replies, xml ) Need Help??

in reply to search for exact string

Hi try this,

use strict; my $toFind="String"; while(<DATA>){ my $line=$_; chomp($line); if($line=~m/\b$toFind(?=[^\w\.]+|$)/i){ print "$line\n"; } }

__DATA__ blah blah string blah important stringstuff we wish to keep Unimportant string more stuff we wish to String.o Some more unimportant String.c


Replies are listed 'Best First'.
Re^2: search for exact string
by oko1 (Deacon) on Mar 27, 2008 at 14:08 UTC

    I'm afraid that your solution is incorrect; "/\b$toFind(?=[^\w\.]+|$)/i" means "match, case-insensitively, a word boundary (1) followed by the content of $toFind followed by (2) EITHER one or more characters which are not 'word-building' characters or literal periods OR the end of the line" - which does not match the specification that was asked for. That is, (1) was never specified (although it was implied) and (2) is simply wrong: you used a positive look-ahead assertion where you should have used a negative look-ahead. As a result, your regex will match, e.g., 'String-' or 'string*'.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://676711]
[tye]: Is it just me, or do most python things have terrible logging/errors?
[LanX]: but but but ... the errors are nicely formatted!
[tye]: 1) The python stack traces show you the names of variables, not the values of variables. Almost never informative.
[LanX]: do you have a py job now?
[tye]: Right now I have errors trying to fetch stuff from graphite. It says 'apps not ready, check startup logs'. I eventually find the startup logs and see 'no apps found'. Looking for fixes to this problem...
[LanX]: no idea ... ask py monks! ;-p
[tye]: it turns out that this can be caused by almost anything going wrong. If you want to know what caused the problem, you have to try to load each app by-hand to see what problems it is having, because none of those will be logged.

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2017-09-21 20:06 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (252 votes). Check out past polls.