1

I have a colum named data, which have string values in different formats like:

55,'first_name','2394234'
'first_name',        '2394234'
'124', 'first_name', '2394234'

I need to extract substring first_name. I'm really bad at SQL, but in python the regex that would extract the first name would be like this:

\'(?P<first_name>[a-zA-Z]{4,})\',\s*\'[0-9]{7}\'

The pattern I need is any combination of letters enclosed in ' ' followed by , after that could be spaces and finally enclosed in ' ' again a number of length 7.

Please any clues would be great.

PepperoniPizza
  • 8,842
  • 9
  • 58
  • 100
  • MySQL does not have direct implementation of `REGEX REPLACE` functionality. Have a look here http://stackoverflow.com/questions/986826/how-to-do-a-regular-expression-replace-in-mysql for possible work-arounds. – PM 77-1 Jun 04 '13 at 16:44
  • That is an option, but as I remember UDF regex need compiling something into Mysql and that is not an option for me at the moment. – PepperoniPizza Jun 04 '13 at 19:31
  • 1
    The udf regex module doesn't need to be compiled 'into' mysql, you compile it as a shared lib, put it in a dir that mysql will be able to see, (in it's dynamic library dir?) , restart the server and then run a couple commands to register it. FWIW. It's not as terrible as having to compile it in if that makes it any easier for you. – synthesizerpatel Jun 05 '13 at 07:14
  • 1
    You might take a look at http://stackoverflow.com/questions/1096679/can-mysql-split-a-column, which ultimately directs to the mysql stored procedure @ http://blog.fedecarg.com/2009/02/22/mysql-split-string-function/ – synthesizerpatel Jun 05 '13 at 07:17

0 Answers0