36

URLを含む列を持ついくつかの行を含むテーブルがあります。URLの形式は次のとおりです。

http://one.example1.com:9999/dotFile.com

http://example2.com/dotFile.comその列のすべての一致を、:9999以降のすべてを保持しながらに置き換えたいと思います。regexp_matchesとregexp_replaceに関するドキュメントをいくつか見つけましたが、頭を完全に包み込むことはできません。

4

2 に答える 2

64

固定文字列を置き換えるには、単純なreplace()関数を使用します。

regexp_replace()動的文字列を置き換えるには、次のように使用できます。

UPDATE
  YourTable
SET
  TheColumn = regexp_replace(
    TheColumn, 'http://[^:\s]+:9999(\S+)', 'http://example2.com\1', 'g'
  )
于 2012-07-30T14:04:23.183 に答える
36

URLがわかっている場合は、正規表現を使用する必要はありません。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

あなたは試すことができます:

UPDATE yourtable SET
  yourcolumn = replace(yourcolumn, 'one.example1.com:9999','example2.com')
;
于 2012-07-30T14:04:06.720 に答える