正则表达式搜索并替换SQL脚本

时间:2014-08-26 05:34:30

标签: sql regex

我有一堆SQL脚本可以执行此操作:

COALESCE([18], 0),COALESCE([19], 0),COALESCE([20], 0),COALESCE([21], 0) ect

有没有办法使用正则表达式来更新它们来执行此操作:

COALESCE([18], 0) as [18], COALESCE([19], 0) as [19], COALESCE([20], 0) as [20], COALESCE([21], 0) as [21]

2 个答案:

答案 0 :(得分:1)

<强>查找

[^()]+\(\[(\d+)\][^)]+\)

<强>替换

$0 AS [$1]

演示:

Regular expression visualization

Debuggex Demo

答案 1 :(得分:1)

(.*?(\[\d+\]).*?\))

这也可以。

参见演示。

http://regex101.com/r/wE4xX6/2