in reply to RegEx - match !foo followed by foo
Which produces the following output.#!/usr/local/bin/perl -w # use strict; # Make some building blocks. What we want at the start; what we don't +want # after "foobar:" using a negative look-ahead assertion; any five # characters; what we want at the end (which we will discard later). # our $rxFooBar = qr{foobar:}; our $rxNotGonkish = qr{(?!(?:g(?:o(?:n(?:k)*)*)*|@))}; our $rxFive = qr{.{1,5}}; our $rxGonk = qr{(?:gonk|@)}; # Put the building blocks together using "()" to capture everything ex +cept # the "gonk" or "@" at the end; # our $rxPutItAllTogether = qr{($rxFooBar$rxNotGonkish$rxFive)$rxGonk}; while(<DATA>) { chomp; print "$_\n"; print /$rxPutItAllTogether/ ? "$1\n\n" : "Failed\n\n"; } __END__ foobar:hellogonk foobar:gonk foobar:higonk foobar:helloworldgonk foobar:ggonk foobar:gogonk foobar:gongonk foobar:gonkgonk foobar:gonkygonk foobar:@gonk foobar:its@ foobar:toomany@
Cheers,foobar:hellogonk foobar:hello foobar:gonk Failed foobar:higonk foobar:hi foobar:helloworldgonk Failed foobar:ggonk Failed foobar:gogonk Failed foobar:gongonk Failed foobar:gonkgonk Failed foobar:gonkygonk Failed foobar:@gonk Failed foobar:its@ foobar:its foobar:toomany@ Failed
JohnGG
|
|---|