sql - Regular expression for whether a string can be made from a set of letters -


i'm in process of making scrabble helper, can enter letters , see words can made them. have mysql table containing of words i'm failing on retrieving them. here's have far:

select     word     dictionary     word regexp '^[example]*$' 

but doesn't work in return words contain more 1 a, example. there way can achieve this?

(i'm open methods don't use regular expressions, although seems though regular expressions best way this).

here's a solution; there's surely room optimization:

declare @word  varchar(8) = 'stack' declare @avail varchar(8) = 'ackst'  declare @letters table     (     letter  char(1) not null primary key,     numneeded   int not null,     numavailable    int not null     ) insert @letters (letter, numneeded, numavailable)     select         r.letter, r.numneeded, coalesce(a.numavailable, 0) numavailable                 (             select                 letter, count(*) numneeded                             (                 select upper(substring(@word, n.number, 1)) letter                 numbers n                 n.number between 1 , len(@word)                 ) x             group                 letter             ) r         left join             (             select                 letter, count(*) numavailable                             (                 select upper(substring(@avail, n.number, 1)) letter                 numbers n                 n.number between 1 , len(@word)                 ) x             group                 letter             ) on r.letter = a.letter  select case when exists (select * @letters numneeded > numavailable) 'no' else 'yes' end ok 

note you'll need numbers table.


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -