[英]REGEXP_SUBSTR with a URL
I have a string in which I'm trying to extract a URL from.我有一个字符串,我试图从中提取 URL 。 When I run it on this RegEx site , it works fine.当我在这个 RegEx 网站上运行它时,它运行良好。
The Regex Pattern is: http:\/\/GNTXN.US\/\S+
正则表达式模式是: http:\/\/GNTXN.US\/\S+
The message I'm extracting from is below, and lives in a column called body
in my SQL database.我从中提取的消息如下,并且位于我的 SQL 数据库中名为body
的列中。
Test Message: We want to hear from you! Take our 2022 survey & tell us what matters most to you this year: http://GNTXN.US/qsx Text STOP 2 stop/HELP 4 help
But when I run the following in SQL:但是当我在 SQL 中运行以下命令时:
SELECT
body,
REGEXP_SUBSTR(body, 'http:\/\/GNTXN.US\/\S+') new_body
FROM
table.test
It returns no value.它不返回任何值。 I have to imagine it's something to do with the backslashes in the URL, but I've tried everything.我不得不想象这与 URL 中的反斜杠有关,但我已经尝试了一切。
The new_body
output should read as http://GNTXN.US/qsx
new_body
output 应该读作http://GNTXN.US/qsx
In mysql you just need to escape the \
在 mysql 中,您只需要转义\
select body, REGEXP_SUBSTR(body, 'http:\\/\\/GNTXN.US\\/\\S+') as new_body
from table.test;
new_body output: new_body output:
http://GNTXN.US/qsx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.