This page
has a great example using REGEXP to do pattern matching. the problem with REGEXP won t match the following strings:
- "Mr John"
- "Dr. John"
or even: - "Mr. John Doe"
with the string "John Doe"
I would like to know how do I get positive matches for any of the given examples?
Here is a sample code:
Drop table Names;
CREATE TABLE Names (
first_name VARCHAR(20),
last_name VARCHAR(20)
);
INSERT INTO Names VALUES ( John , Doe );
INSERT INTO Names VALUES ( Sue , Yin );
INSERT INTO Names VALUES ( Diego James , Franco );
select * from Names;
/*To find names containing a string */
/*I want this to march John Doe*/
SELECT * FROM Names WHERE first_name REGEXP Mr John ;
/*This has John misspelled, I want it to match John Doe */
SELECT * FROM Names WHERE first_name REGEXP Hohn AND last_name REGEXP Doe ;
/*And this would match Diego James Franco*/
SELECT * FROM Names WHERE first_name REGEXP Dr Diego AND last_name REGEXP Franco ;
-Thank you
UPDATE: Thank you for the answers, the question is not how to use regular expression to do the matching that I want, but rather how can I do it regardless of REGEXP. I use REGEXP as an example of pattern matching. I do appreciate the clarification on regular expressions.