![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
How can I use REGEXP to REPLACE characters in a string? Lets assume I have a string like this: 'abc xyz 123 879-890' and I want to remove any character that is NOT a number. The result should be '123879890'. In C# it would be quite simple: string s = Regex.Replace("abc xyz 123 879-890", @"[^0-9\+]", ""); Is there anything equivalent in SQL?? (I tried with the REPLACE() function like select replace ('abc xyz 123 879-890', regexp '[^0-9]', '') but this gets me a syntax error. Many thanks Tom |
#3
| |||
| |||
|
|
The SQL Standard contains the TRANSLATE_REGEX() function: regex transliteration> ::= TRANSLATE_REGEX <left paren XQuery pattern> [ FLAG <XQuery option flag> ] IN <regex subject string [ WITH <XQuery replacement string> ] [ FROM <start position> ] [ USING <char length units> ] [ OCCURRENCE <regex transliteration occurrence> ] left paren but SQL Anywhere does not support this function at this time. Glenn at wrote: How can I use REGEXP to REPLACE characters in a string? Lets assume I have a string like this: 'abc xyz 123 879-890' and I want to remove any character that is NOT a number. The result should be '123879890'. In C# it would be quite simple: string s = Regex.Replace("abc xyz 123 879-890", @"[^0-9\+]", ""); Is there anything equivalent in SQL?? (I tried with the REPLACE() function like select replace ('abc xyz 123 879-890', regexp '[^0-9]', '') but this gets me a syntax error. Many thanks Tom |
![]() |
| Thread Tools | |
| Display Modes | |
| |