Sponsored Content
Full Discussion: Scrabble Regex Help
Top Forums UNIX for Dummies Questions & Answers Scrabble Regex Help Post 302787745 by sudon't on Saturday 30th of March 2013 01:24:41 PM
Old 03-30-2013
Scrabble Regex Help

Hi!
I use an and grep to play Scrabble and other word games because it helps me practice regexes, or, as my friends would say, because I'm a cheater.
Anyway, I'm trying to work out how to write a regex that might do what I want, so let's see if I can explain it properly. Let's say we want to play down. We have a letter, F, followed by three spaces, then a D, which is at the end of the board. The space below the F is a DW, so we want to play it, if possible. We have plenty of room above the F, but we can only play two spaces below F if we can't use the D, three if we can use the D. I have attached a screen-shot of the board if you're having a hard time visualizing it. I have already played "famed."
So, here's the regex I tried:
Code:
an -w -m3 -d twl 'qreraumfd' |grep -E '.*f.{1,3}d?$'

We anagram my rack, plus the F and D, and pipe it to grep. Here we're saying we can have one to three characters after the F, and the D can be there or not. While it returns many usable results, it also returns results which ignore the D. For instance:
Code:
fard
farm
fear

which can't be used because you'd have "fardd" or "farmd", and so on.
Perhaps you are thinking, "Why not just ignore the four-letter words it returns?" And certainly I could pipe it to grep one more time to eliminate them, but I want to know if I can do it all in one grep ERE.
I've tried it a few different ways, but can't quite work it out:
Code:
an -w -m3 -d twl 'qreraumfd' |grep -E '.*f.{1,2}.?d?$'

returns identical results.
What do you think? Is it possible?
Scrabble Regex Help-scrabblejpg
 

4 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Converting perl regex to sed regex

I am having trouble parsing rpm filenames in a shell script.. I found a snippet of perl code that will perform the task but I really don't have time to rewrite the entire script in perl. I cannot for the life of me convert this code into something sed-friendly: if ($rpm =~ /(*)-(*)-(*)\.(.*)/)... (1 Reply)
Discussion started by: suntzu
1 Replies

2. UNIX for Dummies Questions & Answers

Scrabble (SED)

Hello everyone, I've been struggling with an assignement for school for quite some time now and I decided to make a thread here. The goal of the script is to return all the words that can be created with a certain combination of letters that can be given as an argument for the shellscript. It's... (1 Reply)
Discussion started by: iFaceDive
1 Replies

3. Shell Programming and Scripting

Perl, RegEx - Help me to understand the regex!

I am not a big expert in regex and have just little understanding of that language. Could you help me to understand the regular Perl expression: ^(?!if\b|else\b|while\b|)(?:+?\s+){1,6}(+\s*)\(*\) *?(?:^*;?+){0,10}\{ ------ This is regex to select functions from a C/C++ source and defined in... (2 Replies)
Discussion started by: alex_5161
2 Replies

4. Shell Programming and Scripting

Sendmail K command regex: adding exclusion/negative lookahead to regex -a@MATCH

I'm trying to get some exclusions into our sendmail regular expression for the K command. The following configuration & regex works: LOCAL_CONFIG # Kcheckaddress regex -a@MATCH +<@+?\.++?\.(us|info|to|br|bid|cn|ru) LOCAL_RULESETS SLocal_check_mail # check address against various regex... (0 Replies)
Discussion started by: RobbieTheK
0 Replies
Tie::Hash::Regex(3pm)					User Contributed Perl Documentation				     Tie::Hash::Regex(3pm)

NAME
Tie::Hash::Regex - Match hash keys using Regular Expressions SYNOPSIS
use Tie::Hash::Regex; my %h; tie %h, 'Tie::Hash::Regex'; $h{key} = 'value'; $h{key2} = 'another value'; $h{stuff} = 'something else'; print $h{key}; # prints 'value' print $h{2}; # prints 'another value' print $h{'^s'}; # prints 'something else' print tied(%h)->FETCH(k); # prints 'value' and 'another value' delete $h{k}; # deletes $h{key} and $h{key2}; or (new! improved!) my $h : Regex; DESCRIPTION
Someone asked on Perlmonks if a hash could do fuzzy matches on keys - this is the result. If there's no exact match on the key that you pass to the hash, then the key is treated as a regex and the first matching key is returned. You can force it to leap straight into the regex checking by passing a qr'ed regex into the hash like this: my $val = $h{qr/key/}; "exists" and "delete" also do regex matching. In the case of "delete" all vlaues matching your regex key will be deleted from the hash. One slightly strange thing. Obviously if you give a hash a regex key, then it's possible that more than one key will match (consider c<$h{qw/./}>). It might be nice to be able to do stuff like: my @vals = $h{$pat}; to get all matching values back. Unfortuately, Perl knows that a given hash key can only ever return one value and so forces scalar context on the "FETCH" call when using the tied interface. You can get round this using the slightly less readable: my @vals = tied(%h)->FETCH($pat); ATTRIBUTE INTERFACE From version 0.06, you can use attributes to define your hash as being tied to Tie::Hash::Regex. You'll need to install the module Attribute::Handlers. METHODS
FETCH Get a value from the hash. If there isn't an exact match try a regex match. EXISTS See if a key exists in the hash. If there isn't an exact match try a regex match. DELETE Delete a key from the hash. If there isn't an exact match try a regex match. AUTHOR
Dave Cross <dave@mag-sol.com> Thanks to the Perlmonks <http://www.perlmonks.org> for the original idea and to Jeff "japhy" Pinyan for some useful code suggestions. COPYRIGHT
Copyright (C) 2001-8, Magnum Solutions Ltd. All Rights Reserved. LICENSE
This script is free software; you can redistribute it and/or modify it under the same terms as Perl itself. SEE ALSO
perl(1). perltie(1). Tie::RegexpHash(1) perl v5.10.0 2008-06-30 Tie::Hash::Regex(3pm)
All times are GMT -4. The time now is 09:14 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy