Can MySQL replace multiple characters?

前端 未结 6 2069
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-27 05:42

I\'m trying to replace a bunch of characters in a MySQL field. I know the REPLACE function but that only replaces one string at a time. I can\'t see any appropriate function

6条回答
  •  情深已故
    2020-11-27 06:18

    I've been using lib_mysqludf_preg for this which allows you to:

    Use PCRE regular expressions directly in MySQL

    With this library installed you could do something like this:

    SELECT preg_replace('/(\\.|com|www)/','','www.example.com');
    

    Which would give you:

    example
    

提交回复
热议问题