2011-10-10 42 views
0

我知道MySQL没有正则表达式替换函数,但我想知道是否有人写过我可以使用的用户定义函数?我知道只是要求代码的答案并不好,但我对MySQL并不熟练,只是寻求一些帮助。如果没有,我可以接受。MySQL正则表达式替换?

由于

+0

什么是你想用的替换功能呢? –

+0

可能重复的[如何在MySQL中执行正则表达式替换?](http://stackoverflow.com/questions/986826/how-to-do-a-regular-expression-replace-in-mysql) – tadman

回答

1
+0

这听起来很奇怪大。它需要安装一个库来使用Perl正则表达式,但它是一个有效的解决方案。 – Bobbake4

+0

或者,请参阅https://launchpad.net/mysql-udf-regexp,该文章在@tadman记录的帖子中推荐使用。 – imm

0
select 
    replace(replace(replace(replace(replace( 
    replace(replace(replace(replace(replace( 
    replace(replace(replace(replace(replace( 
    replace(replace(replace(replace(replace( 
    replace(replace(replace(replace(replace( 
    replace(replace(replace(replace(replace( 
    replace(replace(replace(replace(replace( 
    replace(replace(replace(

'a~b}c{d`e_f^g\\h[i?j=k;l.m-n,o*p(q&r$s"t u|v][email protected]>z<:+)\'%#!\r\f\v\naz\t09\b', 

    '~', ''), '}', ''), '{', ''), '`', ''), '_', ''), 
    '^', ''), '\\', ''), '[', ''), '?', ''), '=', ''), 
    ';', ''), '.', ''), '-', ''), ',', ''), '*', ''), 
    '(', ''), '&', ''), '$', ''), '"', ''), ' ', ''), 
    '|', ''), ']', ''), '@', ''), '>', ''), '<', ''), 
    ':', ''), '+', ''), ')', ''), '\'', ''), '%', ''), 
    '#', ''), '!', ''), '\r', ''), '\f', ''), '\v', ''), 
    '\n', ''), '\t', ''), '\b', '') 

替换

A〜B} 13 C {d`e_f ^克\ H [I J = k; lm-n,o * p(q & r $ s“t u | v] x @ y> z <:+)\'%#!\ r \ f \ v \ naz \ t09 \ b

abcdeghijklmnopqrstuxyzaz09

MySQL - Regular Expressions & REPLACE