daled Posted July 15, 2007 Share Posted July 15, 2007 I'm using REGEXP to search a database. Is there a way to order the results in the order of how well they match the original expression? Quote Link to comment https://forums.phpfreaks.com/topic/60109-regexp/ Share on other sites More sharing options...
fenway Posted July 16, 2007 Share Posted July 16, 2007 Not really, regexp support in mysql blows, it's just a simple binary match. Quote Link to comment https://forums.phpfreaks.com/topic/60109-regexp/#findComment-299510 Share on other sites More sharing options...
Wildbug Posted July 16, 2007 Share Posted July 16, 2007 You could use multiple regular expressions and add the matches (0 if no match, 1 if match), and the more that match will be ordered higher. SELECT (col1 RLIKE 'a[bc]') + (col1 RLIKE 'xz[0-9]$') + (col1 RLIKE '^55') AS score FROM table WHERE col1 RLIKE 'a[bc]' OR col1 RLIKE 'xz[0-9]$' OR col1 RLIKE '^55' ORDER BY score DESC, col1 Quote Link to comment https://forums.phpfreaks.com/topic/60109-regexp/#findComment-299531 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.