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

    Join Date
    Mar 2009
    Posts
    14
    Rep Power
    0

    Exclamation RegExp + MySQL tricky problem


    Hi!

    I consider myself a fairly good programmer, but regular expressions have never been my speciality. And now I have run into a tricky problem.

    Let's say I have a database with a large table containing different words. I am given an array of characters, let's say "asdfg". Now, I want to extract all words from the database containing these characters, and I want to do it in one query using regular expressions to make it fast.

    The catch: I can only use each character once, and all characters does not have to be used.

    This is my approach so far, but it still allows characters to be used more than once:

    Code:
    SELECT * FROM tblwords WHERE wWord REGEXP '^[asdfg]{1,}$'
    And the bonus:
    Let's say i'm given a wildcard: "asdfg*". The wildcard can work as any character, and I can be given several wildcards, apart from that it's the same problem.


    Anyone got a good idea?
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,846
    Rep Power
    6351
    I doubt there's a way to do this in regex alone. You can use the rlike function to pull out all the items that might be matches, then use a programming language to determine the uniqueness of the characters.

    -Dan
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo