我有一个表,其中包含许多行,其中包含一个包含URL的列.URL的格式如下:
http://one.example1.com:9999/dotFile.com
我希望替换该列中的所有匹配项,http://example2.com/dotFile.com同时保留以下内容后的所有内容:9999.我在regexp_matches和regexp_replace上找到了一些文档,但我无法完全理解它.
Tom*_*lak 59
要替换固定字符串,请使用简单replace()函数.
要替换动态字符串,您可以regexp_replace()像这样使用:
UPDATE
YourTable
SET
TheColumn = regexp_replace(
TheColumn, 'http://[^:\s]+:9999(\S+)', 'http://example2.com\1', 'g'
)
Run Code Online (Sandbox Code Playgroud)
Ken*_*ent 31
如果你知道网址,你不必使用正则表达式.replace()函数应该适合你:
replace(string text, from text, to text)
Replace all occurrences in string of substring from with substring to
example: replace('abcdefabcdef', 'cd', 'XX') abXXefabXXef
Run Code Online (Sandbox Code Playgroud)
你可以尝试:
replace(yourcolumn, 'one.example1.com:9999','example2.com')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
40167 次 |
| 最近记录: |