2011-10-10 36 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