Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.

share|improve this question
 
MySQL does not have direct implementation of REGEX REPLACE functionality. Have a look here stackoverflow.com/questions/986826/… for possible work-arounds. –  PM 77-1 Jun 4 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 4 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 5 at 7:14
1  
You might take a look at stackoverflow.com/questions/1096679/can-mysql-split-a-column, which ultimately directs to the mysql stored procedure @ blog.fedecarg.com/2009/02/22/mysql-split-string-function –  synthesizerpatel Jun 5 at 7:17

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.