用于删除所有空格和数字的正则表达式
Regexp for removing all spaces and digits
我正在尝试在 sql 语句中使用正则表达式从字符串 'text' 中删除所有 space 和数字,这可能看起来像
1. 000000123456 (No space)
2. 00000 123456 (spaces in the beginning and end of string)
3. 90330000 45 (2 spaces at the end)
到目前为止,我已经能够提出以下解决方案:
select regexp_replace('text','\s(^[0-9]*)\s','\1')
select regexp_replace('text','[[:blank:]]+[^[0-9]*][[:blank:]]+','\1')
我得到的结果是:
1. 000000123456
2. 00000 123456
3. 90330000 45
我按原样得到文本。如果我尝试使用
删除数字
regexp_replace('text','^[0-9]*','\1'),
它工作正常 - 所有数字都被删除并且值结果为“”(空)。但是带有 spaces 的文本不会删除数字和 space。
我做错了什么?
尝试使用包含数字和空格的字符 class:
regexp_replace('text', '[0-9\s]+', '')
这应该会删除所有数字和空格。但是,还不完全清楚您要做什么,因为您没有在上下文中向我们展示数字。
我正在尝试在 sql 语句中使用正则表达式从字符串 'text' 中删除所有 space 和数字,这可能看起来像
1. 000000123456 (No space)
2. 00000 123456 (spaces in the beginning and end of string)
3. 90330000 45 (2 spaces at the end)
到目前为止,我已经能够提出以下解决方案:
select regexp_replace('text','\s(^[0-9]*)\s','\1')
select regexp_replace('text','[[:blank:]]+[^[0-9]*][[:blank:]]+','\1')
我得到的结果是:
1. 000000123456
2. 00000 123456
3. 90330000 45
我按原样得到文本。如果我尝试使用
删除数字regexp_replace('text','^[0-9]*','\1'),
它工作正常 - 所有数字都被删除并且值结果为“”(空)。但是带有 spaces 的文本不会删除数字和 space。
我做错了什么?
尝试使用包含数字和空格的字符 class:
regexp_replace('text', '[0-9\s]+', '')
这应该会删除所有数字和空格。但是,还不完全清楚您要做什么,因为您没有在上下文中向我们展示数字。