SQL正则表达式仅替换整个短语
什么是SQL查询来替换“仅限整个短语”的betwen运算符 我的意思是:SQL正则表达式仅替换整个短语,sql,regex,sql-server-2008-r2,replace,Sql,Regex,Sql Server 2008 R2,Replace,什么是SQL查询来替换“仅限整个短语”的betwen运算符 我的意思是: @text = 'First +Last /(toto salary *0.07)' 但当: replace(@text , 'toto salary','bobo salary') result : 'First +Last /(bobo salary *0.07)' 换言之,替换“*+/-()”运算符之间的短语,以下操作可能有效: replace(@text , 'toto','') NO result
@text = 'First +Last /(toto salary *0.07)'
但当:
replace(@text , 'toto salary','bobo salary')
result : 'First +Last /(bobo salary *0.07)'
换言之,替换“*+/-()”运算符之间的短语,以下操作可能有效:
replace(@text , 'toto','')
NO result because not match whole phrase ('toto salary')
诀窍是在你想要保留的强制性部分周围加上括号,
在本例中,使用
/(
和*0.07)
,然后通过在替换表达式中添加\1
和\2
等来包含这些部分。您使用哪种RDBMS?不幸的是,regexp\u replace
在SQL Server中不可用在执行替换之前添加占位符:replace('/(toto工资’,‘/(bobo工资’)
select regexp_replace( 'First +Last /(toto salary *0.07)' , '(/\()toto salary( [*][0-9]+[.]?[0-9]*\))','\1bobo salary\2') from dual;