in reply to How do a make an IP look up non-greedy?

There are two independent things that could cause problems here.

Firstly, IP addresses contain .s which are significant in regexps. You can avoid this issue by using \Q and \E in the regexp itself (as suggested above, but without explaining why) or quotemeta outside it.

Secondly, the problem you actually identified! Searching for "18" will match against "180", etc. This is fixed with the \b in the regexp (also suggested above) meaning word "boundary".

Hope that helps.

--
use JAPH;
print JAPH::asString();

  • Comment on Re: How do a make an IP look up non-greedy?

Replies are listed 'Best First'.
Re^2: How do a make an IP look up non-greedy?
by AnomalousMonk (Archbishop) on Jun 16, 2009 at 11:53 UTC
    I agree that metacharacter quoting and nailing down the match to the start of the string with the  ^ anchor are prudent, but my own personal preference would be to use the  \D (non-digit) character class rather than the  \b boundary assertion since this most clearly expresses the intent of the match: no decimal digit follows '18'. (If the IP might lie at the end of the string, I would even be tempted to use a  (?!\d) "negative look-ahead to a digit", although this is arguably "messier" than a simple  \b assertion.)