如何在 postgresql 中删除 /* */ 之间的字符

问题描述 投票:0回答:3

我想从字符串中删除 /**/ 之间的字符

例子:

转换字符串

“select * from food where /* id = 1 and */ food_code = 2”

“从 food_code = 2 的食物中选择 *”

postgresql regexp-replace
3个回答
0
投票

可以这样做

select regexp_replace('select * from food where /* id = 1 and */ food_code = 2', '\/\*.+\*\/', '','g');

转义“/”和“*”。


0
投票

我们可以使用积极的后视

(?<=re)
和积极的前瞻
(?=re)

这将捕获并删除多个 /.+/

select regexp_replace(string, '\/\*(?<=\/\*)(.*?)(?=\*\/)\*\/','', 'g')
from mytable

这里演示


-1
投票

任何人都可以帮助我......................?

© www.soinside.com 2019 - 2024. All rights reserved.