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
In reply to Oddity with Conditional Regex by Rabscuttle
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |