On Thu, Oct 30, 2008 at 10:56 AM, Brent Clark <[EMAIL PROTECTED]>wrote:

> Hiya
>
> I have three sentences.
>
> This is a nice hotel.
> The view & food is good.
> We are at the Victoria & Alfred Hotel.
>
> I need a perl regex / code to not print out sentence 2 (basically fail).
>
> This is what I so far.
>
> print $_  if $_ !~ /\&|Victoria \&/ig;
>
> Im struggling to get this right.
>
> TIA.
>
> Regards
> Brent Clark
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> http://learn.perl.org/
>
>
>

Hi Brent,

I just tried this and found that you where nrealy there.

#!/usr/local/bin/perl
use strict;
use warnings;
my @text = ('This is a nice hotel.', 'The view & food is good.', 'We are at
the Victoria & Alfred Hotel.');
foreach ( @text ) {
 print $_ . "\n" if ( $_ !~ /(?<!Victoria) \&/i );
}
Prints:
This is a nice hotel.
We are at the Victoria & Alfred Hotel.

What the (?<!Victoria) bit does is nothing at first the & gets matched and
then the (?<!Victoria) bit kicks in and checks to see if the string
Victoriais not (thats the !'s doing use and = to require it) infront
of the &.

Try having a look at
perlretut<http://perldoc.perl.org/perlretut.html#Backreferences> for
more information on how this works.

Reagrds,

Rob

Reply via email to