1 message in com.mysql.lists.mysqlQuestion: REPLACE function
FromSent OnAttachments
Tim Gustafson06 Jan 2002 19:44 
Subject:Question: REPLACE function
From:Tim Gustafson (ti@falconsoft.com)
Date:01/06/2002 07:44:41 PM
List:com.mysql.lists.mysql

Hello

I have a question about the REPLACE string function, not the REPLACE SQL command.

According to the documentation, REPLACE works as follows:

========== REPLACE(str,from_str,to_str) Returns the string str with all all occurrences of the string from_str replaced by the string to_str

mysql> select REPLACE('www.mysql.com', 'w', 'Ww'); -> 'WwWwWw.mysql.com' ==========

Is there any way to make this REPLACE function match regular expressions rather than substrings? Lets say, if you wanted to remove all non-alhpabetic characters from a column, you could do:

select REPLACE(Address, '[^A-Za-z]', '');

so that '123 Somestreet' becomed 'Somestreet'?

The real usefullness of this, for me, is to be able to group rows together by similarities in their columns. For example:

select REPLACE(Address, '[^A-Za-z]', '') as StreetName, COUNT(*) from Addresses group by StreetName;

which would return something like this:

+-------------+----------+ | Street Name | COUNT(*) | +-------------+----------+ | Somestreet | 5 | | Apple Ct | 2 | +-------------+----------+

Thanks in advance for any help. At the worst case, I guess this is a request for a feature.

Tim