PHP regex, character match word

Hi

This is a bit embarrasing. Maybe i’m tired…but:

If I want to match these characters: abc
with these “words”: abc cba cab acb bac

How do I do this in regex? Let’s say I got an array with words, and I want my 3 characters to match any word that contain these 3 characters.

Thanks for any help. :slight_smile:

Please elaborate your question, I don’t fully understand what you are asking and I’ms ure nobody else is as there’s been post views but no replies…

Alright. I’ll try once more:

I can use wordfeud/scrabble as example.

If I got these letters: O L N R A O P
And I want to find words from an array (wordlist) that contains letters from above.

From ‘O L N R A O P’ I can get the word Pool, Loan and maybe others. How do I do this?

//Load array
//Letter input
//Search array for words that contains the letters. Ex ‘O L N R A O P’ match the word POOL
//Put this in a foreach loop to spit out every word that matches letters from the input

Is this the right approach ? Can I do this with regex, or is there any other way ?

I’m not making any wordfeud/scrabble cheating engine… but I just want to learn how to do this. And probably using this for other script(s).

Seems you’re looking to make something like this? http://grecni.com/texttwist.php

It uses a wordlist/dictionary file to see all possible words a bunch of characters can make up.

Try something like this to show all the letters to work with and then plug it into your wordlist:


$word = "lpoo";
foreach (count_chars($word , 1) as $i => $val) {
echo chr($i)."<br/>";
}

Yeah, something like this!

hmm, one problem with that code is that it removes letters that is more than 1.

It echo’s:
l
o
p

Example of what I am looking for:
http://feudfraud.com/en/

Found something, both in php, perl and JS:
http://ejohn.org/blog/dictionary-lookups-in-javascript/

The JS script is what I’m looking for. So my problem is solved.

Thanks for answers