Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!ucbvax!iWarp.intel.com!news From: merlyn@iWarp.intel.com (Randal L. Schwartz) Newsgroups: comp.lang.perl Subject: Re: regular expressions Message-ID: <1991Jun6.181655.16709@iWarp.intel.com> Date: 6 Jun 91 18:16:55 GMT References: <1991Jun4.175023.6509@serval.net.wsu.edu> <1991Jun6.162325.18139@cs.cmu.edu> Sender: news@iWarp.intel.com Reply-To: merlyn@iWarp.intel.com (Randal L. Schwartz) Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 22 In-Reply-To: jm36@hogtown.andrew.cmu.edu (John Gardiner Myers) Nntp-Posting-Host: se.iwarp.intel.com In article <1991Jun6.162325.18139@cs.cmu.edu>, jm36@hogtown (John Gardiner Myers) writes: | In article <1991Jun4.175023.6509@serval.net.wsu.edu> hakimian@tek4.eecs.wsu.edu (Karl Hakimian - staff) writes: | >For example, how would you write a regular expression that accepts a string | >with "foo" iff "bar" is not also in the string. | | /^([^b]|b[^a]|ba[^r])*b?a?foo([^b]|b[^a]|ba[^r])*$/ $_ = "bbar foo"; print "wrong" if /^([^b]|b[^a]|ba[^r])*b?a?foo([^b]|b[^a]|ba[^r])*$/; Writing "doesn't match" regexs is a very tricky art. No, I'm not trying to start a contest. You just have to remember that any part of your "not classes" could match something else of some significance in your string. It took me 10 seconds to come up with the string above. $_="Could I be Just another guy who takes Perl and hacks it?"; /(J\w+ \w+).*(P\w+).*(h\w*)s/; print "$1 $2 $3er,"; -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/