Regular Expression search the exact pattern

by Nasser Hajlawi   Last Updated September 04, 2017 19:05 PM

I want to search in MySQL database for words contains a pattern of characters which user submit.
When user submit ofo it will show result of words that contains the submitted character with same number of repetition

example:
User submited 2 o's it will show results for oo,o OR zero(without o) not more than 2.
what i expect:

result I want to show:
foo,fo,of,oo, etc ..
result I don't want to show :
fooo // because it have 3 o's user submit 2 o's<br> ff //because it have double f user submit 1 f


Another Example : user submitted : dofo

    +=====================+
    |        Words        |
    +=====================+
    | foo //true          |
    +---------------------+
    | food   //true       |
    +---------------------+
    | fog   //false       |
    +---------------------+
    | foood  //false      |
    +---------------------+
    | of       //true     |
    +---------------------+
    | oof     //true      |
    +---------------------+



My regular expression for this is ^[dofo]+$ it is showing results with characters repetition Like fooo ooof fff ooff



Related Questions