开发者

extract value using regular expression in mysql

开发者 https://www.devze.com 2022-12-16 13:40 出处:网络
I am storing values in database like this www/content/lessons/40/Digital Library/document1.doc 开发者_运维技巧

I am storing values in database like this

www/content/lessons/40/Digital Library/document1.doc
开发者_运维技巧

I need to extract the file document.doc.

How to retrieve this value from mysql using regular expression.


you not need to use regexp (low performence) use substring_index instead

SELECT SUBSTRING_INDEX('bbb/bbbbbb/bbbbbbbbb/bbbb', '/', -1);

link :

http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_substring-index


Mysql does not provide regex based extraction from strings, but you can extend mysql to do this:

https://github.com/mysqludf/lib_mysqludf_preg

It's not a good solution for a lot of people though. eg you couldn't use it in a shared hosting environment.

0

精彩评论

暂无评论...
验证码 换一张
取 消