我有一列“逐字”,其中每个条目包含多行。这是一个例子:
Dummy field1:Text
Tell Us More:Text to capture
Dummy field2:Text
我只想捕获第二行 Tell Us More:
中的 Text to capture
文本,并将该值放入列 verbatim_scrubbed
。在上面的示例中,Text to capture
将是 verbatim_scrubbed
中的条目。
我对 postgres 和 regexp
不是很好,所以我希望有人能帮助我。正在考虑类似于以下内容的内容:
update TABLE
set verbatim_trimmed = array_to_string(regexp_matches(verbatim,'tell us more:(.*)','gi'));
这行不通,但我觉得类似的东西可能有用。
最佳答案
也许有一种直接的方法来捕获:Text to capture
without the cariage return \r
and the new line \n
charracters (不使用 regexp_replace )。
以下是您可以执行的操作:
select regexp_replace(array_to_string(regexp_matches(verbatim, '^Tell Us More:(.*)$','n'),'',''), E'[\\r\\n]', '' ) from my_table;
关于regex - 使用正则表达式从 postgres 中的多行条目中修剪文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26809567/