Rabscuttle has asked for the wisdom of the Perl Monks concerning the following question:
Hello!
Something is going wrong in my regular expression. It works properly when I include the (?{print;}) diagnostic parts, but when I remove them that part of the regex always returns true.
It's meant to be part of a scrabble program. Given a space on the board (in this example <space><space>W) and a set of tiles (ORW), it matches words that can be played in that spot.
for( qw(row bow sow how wow crw stw wrw)) { print "$_\n"; if(/ (?(?=(.*o){1}) (?{print "there's an o!\n";}) (?(?!(.*r){1}) (?{print "there's no r!\n";}) (?=(.*w){2}) (?{print "there's two ws!\n";}) | (?{print "there's an r!\n";}) ) | (?{print "there's no o!\n";}) (?=(.*w){2}) (?{print "there's 2 ws!\n";}) (?=(.*r){1}) (?{print "there's an r!\n";}) ) ^..W$ /xi) { print "YES\n\n"; } else { print "NO\n\n"; } }
I'm pretty sure this was working some time ago when I had an earlier version of perl, but I've since updated to 5.10.0 and now it's not.
Thanks for any help
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Oddity with Conditional Regex
by JavaFan (Canon) on Nov 12, 2008 at 13:34 UTC | |
by almut (Canon) on Nov 12, 2008 at 13:57 UTC | |
by ikegami (Patriarch) on Nov 12, 2008 at 21:07 UTC | |
by almut (Canon) on Nov 12, 2008 at 22:32 UTC | |
by ikegami (Patriarch) on Nov 13, 2008 at 13:30 UTC | |
| |
|
Re: Oddity with Conditional Regex
by JadeNB (Chaplain) on Nov 12, 2008 at 19:55 UTC |