我有一列包含地址信息。我想删除#
和,
之间的所有内容,但也要删除#
并保留,
。
编辑:我还需要删除#
前的空格。
这是我的专栏的样子:
ADDRESS
123 abc st. #123, city, zipcode
321 def road #321, city, zipcode
所以我的专栏看起来像这样:
ADDRESS
123 abc st., city, zipcode
321 def road, city, zipcode
答案 0 :(得分:0)
根据您的示例,您还希望删除#
前的空格:
select str, regexp_replace(str, ' #[^,]+,', ',')
from (values ('321 def road #321, city, zipcode')) v(str)
答案 1 :(得分:0)
您可以使用positive lookahead:
select address, regexp_replace(address,' #[^,]+(?=,)','') from foo;
address | regexp_replace :------------------------------- | :-------------------------- 123 abc st. #123, city, zipcode | 123 abc st., city, zipcode 321 def road #321, city, zipcode | 321 def road, city, zipcode
db <>提琴here