Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re^2: Find all strings containing "a" characters, that are not followed by "b" characters.

by johngg (Abbot)
on Dec 12, 2012 at 23:39 UTC ( #1008611=note: print w/replies, xml ) Need Help??


in reply to Re: Find all strings containing "a" characters, that are not followed by "b" characters.
in thread Find all strings containing "a" characters, that are not followed by "b" characters.

A look-ahead is fine, you just have to insert .* (zero or more of anything) before the "b" I think.

$ perl -E ' > say qq{$_ - @{ [ m{a(?!.*b)} ? q{Match} : q{No match} ] }} for ( > q{Have you any fish}, > q{What a nice broom}, > q{Fishing for trout}, > );' Have you any fish - Match What a nice broom - No match Fishing for trout - No match $

I hope this is of interest.

Cheers,

JohnGG

  • Comment on Re^2: Find all strings containing "a" characters, that are not followed by "b" characters.
  • Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1008611]
help
Chatterbox?
choroba's discovered two instances of a weird animal in the code at work: \@$var
[Eily]: hum, tied scalar, generates a new array when derefed ? :D
[Corion]: choroba: Ah, when doing a shallow copy, I prefer [ @$var ] - I think \@$var might return the same reference instead of a reference to a fresh copy
[Corion]: perl -wle "my $ar = [1,2,3]; my $br=\@$ar; print qq($ar / $br)" confirms this to me

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (11)
As of 2017-09-26 08:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    During the recent solar eclipse, I:









    Results (293 votes). Check out past polls.

    Notices?