We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

MySQL: LIKE query for alphanumeric characters

hankknight
hankknight asked
on
Medium Priority
829 Views
Last Modified: 2012-05-11
I want a query for  MySQL that will return results irrespective of any characters except letters and numbers.

All these queries:

SELECT * FROM `XYZ` WHERE `QRS` LIKE '%hello-world%'
SELECT * FROM `XYZ` WHERE `QRS` LIKE '%helloworld%'
SELECT * FROM `XYZ` WHERE `QRS` LIKE '%hello world%'
SELECT * FROM `XYZ` WHERE `QRS` LIKE '%h e l l o w o r l d%'
SELECT * FROM `XYZ` WHERE `QRS` LIKE '%h-el-l-o-w-o-r-l-d%'
SELECT * FROM `XYZ` WHERE `QRS` LIKE '%hello**world%'

Should return matches for "Hellow/Orld"
Comment
Watch Question

Walter RitzelSenior Software Engineer
CERTIFIED EXPERT

Commented:
you can use RLIKE instead of LIKE. Then instead if the simple like pattern, you can use regular expressions.
Here is the link: http://dev.mysql.com/doc/refman/5.5/en/regexp.html
 
Top Expert 2009
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview

Author

Commented:
Thank you both for your comments.  It sounds like regular expressions are the way to go.

However, I don't know how to implement a working regular expression.

This does NOT work:


SELECT * FROM `XYZ` WHERE `QRS` RLIKE  'HelloWorld'

Open in new window

Senior Software Engineer
CERTIFIED EXPERT
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Commented:
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.