Is there any way to access the match text in MySQL rlike selects?

    Hi. I am doing a select like this in MySQL 5:

      
      select * from foo where bar rlike '(.*),(.*)';
      
      


    The specific example here is made up. Anyway, I'd like to be able to get to the matched text from bar, like I can with various languages regexp libraries. Is this functionality exposed at all in MySQL? I've looked at the docs and can't see any indication that it is, so this might just be wishful thinking.

posted at: 08:17 | path: /mysql | permanent link to this entry

    #1 Jeremy Cole

    Nope, no way to do that. MySQL has needed a more robust regexp implementation for a long time...

    #2 Ralph Anseus

    Designing your database around this mechanism would almost certainly imply that you're breaking first normal form. Not saying you can't, but maybe you shouldn't.

    #3 Scott Noyes

    That particular regexp can be replaced easily enough with some calls to SUBSTRING_INDEX.

    Then there's the UDFs from http://udf-regexp.php-baustelle.de/trac/ that will provide what you want in the general case.

    #4 Hartmut Holzgraefe

    I have been working on an UDF module providing Oracle-like REGEXP functions for a while and have finished the implementation of all optional parameters just today (the documentation is still a bit lagging behind thoug)

    http://udf-regexp.php-baustelle.de/trac/

    Add a comment to this post:

    Your name:

    Your email: Email me new comments on this post
      (Your email will not be published on this site, and will only be used to contact you directly with a reply to your comment if needed. Oh, and we'll use it to send you new comments on this post it you selected that checkbox.)


    Your website:

    Comments: