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

    Join Date
    Aug 2006
    Posts
    89
    Rep Power
    0

    Regex match for char in string


    Hi guys,

    Recently i do a project to create the nearest possiblities to match a field in the database and using the REGEXP function in the mySQL.

    The code in the mysql i used below.

    Code:
    SELECT ap_name,no_doc FROM applicant WHERE ap_name REGEXP  '(^.*mohamed ali.*$)'
    What i am trying to do is to get the nearest name to the above field of ap_name.

    In the database exist 2 names which is , mohamed ali and mohamad ali.

    How do i produce the REGEXP code to match with those 2 names.With the code i have now it will only match with mohamed ali.

    Thanks
  2. #2
  3. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,074
    Rep Power
    9398
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Posts
    89
    Rep Power
    0
    Originally Posted by requinix
    Don't use regular expressions: use MATCH... AGAINST instead.
    Thanks for the reply. Yes, i already try do the fulltext method but the result quite dissappointed which is not fulfill the requirement i need. That's why i'm going for REGEX.

    Any other opinions?
  6. #4
  7. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,074
    Rep Power
    9398
    No offense, but you don't know what you're getting into so you don't know now that the regular expression idea is a bad one.

    Define "disappointing".
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2006
    Posts
    89
    Rep Power
    0
    Originally Posted by requinix
    No offense, but you don't know what you're getting into so you don't know now that the regular expression idea is a bad one.

    Define "disappointing".
    That's ok. Would u mind to tell why it is a bad one?
  10. #6
  11. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,074
    Rep Power
    9398
    Let's say you have two words: foo and bar. That's four combinations to search for
    Code:
    foo
    bar
    foo bar
    bar foo
    using two expressions
    Code:
    .*(foo|bar).*
    .*(foo.*bar|bar.*foo).*
    Not too bad. How about three words? 15 combinations
    Code:
    foo
    bar
    baz
    foo bar
    foo baz
    bar foo
    bar baz
    baz foo
    baz bar
    foo bar baz
    foo baz bar
    bar foo baz
    bar baz foo
    baz foo bar
    baz bar foo
    and three expressions
    Code:
    .*(foo|bar|baz).*
    .*(foo.*(bar|baz)|bar.*(foo|baz)|baz.*(foo|bar)).*
    .*(foo.*(bar.*baz|baz.*bar)|bar.*(foo.*baz|baz.*foo)|baz.*(foo.*bar|baz.*foo)).*
    Q. Why all those combinations?
    A. Because when people search they don't expect they have to put the right words in the right order.

    Q. Can't some of those be combined together?
    A. Yeah. That's why there are so fewer regexes for so many combinations.

    Q. I mean even farther than that.
    A. You want the results ranked, right? A better match should rank higher than a worse match so there's one expression for each "level".
  12. #7
  13. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,908
    Rep Power
    6351
    More specifically, what failing of MATCH...AGAINST are you trying to solve with regular expressions?

    -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