#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    1
    Rep Power
    0

    Mysql regex to find fixed lenght words


    I'm trying to find words of four letters from a given set using the next syntax:

    Code:
    SELECT * FROM words WHERE word REGEXP '^[dcqaahii]{4}$'
    and it returns words with just four letters as desired, but the question it's that i do not know how to avoid the regex use one letter more than once. the result returns words with two 'c' and in the set there is only one, so it's not a valid word.

    Is there anything I can include for avoiding it?

    Thanks in advance.
  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,119
    Rep Power
    9398
    There's no easy way to do a search like that.

    The best way to solve the problem would be to store the letter-sorted "word" alongside the regular word.
    Code:
    word      | sorted
    ----------+----------
          cat |       act
         vile |      eilv
         evil |      eilv
    redundant | addennrtu
    portfolio | filoooprt
    Then searching is easy.
    Code:
    ...WHERE word = "eilv"

IMN logo majestic logo threadwatch logo seochat tools logo