
dws
Deleted
Jul 17, 2000, 9:12 AM
Post #7 of 9
(26289 views)
|
Re: regular expression tomfoolery
[In reply to]
|
Can't Post
|
|
"The aim of the code is to match 'bar' that is NOT directly preceeded by 'foo'." A strict read of this says that the string "okbar and foobar" should match, based on the first 'bar'. And the loop unrolling hint does not suggest otherwise. And if all you want to do is reject any line containing "foobar", then next if /foobar/; is sufficient. That's hardly interesting. (Didn't expect this to become a side lesson in requirements analysis, did you? :-) This might be more along the lines of what you're looking for: <BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR> @str = ("no foo bar", "foobar", "fobar", "fofobar", "fooobar", "somebar foobar", "foobar somebar", "otherbar"); for ( @str ) { print; print "*" if /(^.{0,2}bar|f[^o]obar|fo[^o]bar|[a-eg-z]..bar)/i; print "\n"; } </pre><HR></BLOCKQUOTE> [This message has been edited by dws (edited 07-17-2000).]
|