postgresql正则表达式和子字符串

发布于 2024-10-17 14:15:42 字数 446 浏览 2 评论 0原文

我有一个正则表达式 http\:\/\/domainname\.com\/\S{4} 应该捕获如下网址: http://domainname.com/key4< /code> 较长的文本。

我只想获取密钥并将其与 postgres 数据库中的表字段进行匹配。

在尝试了一些东西之后,我来到了这个查询(用于获取密钥):

SELECT substring(infos FROM '[http\:\/\/domainname\.com\/\S{4}]{7}' ) AS key FROM actions

结果我得到了每行的 /domainname.com ...好吧,没有你所看到的密钥。

我做错了什么?

谁能告诉我 {7} 代表什么?

I have a regular expression http\:\/\/domainname\.com\/\S{4} which should catch urls like this: http://domainname.com/key4 in a longer text.

I want to get only the key and match it with a table field in my postgres database.

after trying some stuff I came to this query (for grabbing keys):

SELECT substring(infos FROM '[http\:\/\/domainname\.com\/\S{4}]{7}' ) AS key FROM actions

as a result i get the /domainname.com for each row ... well, no keys as you can see.

what am I doing wrong?

can anyone tell me what the {7} stands for?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怪我入戏太深 2024-10-24 14:15:43

{7} 代表之前模式的 7 倍。因此,在本例中,[] 之间存在不同的字符。即 [abc]{3} 匹配 aaa cba 或任何其他组合。

我相当确定这不是您想要的。您可能正在寻找类似的东西:

SELECT substring('http://domainname.com/key4' from 'http://domainname\\.com/\\S{4}')
FROM actions

The {7} stands for 7 times the previous pattern. So in this case, the different characters between [ and ]. i.e. [abc]{3} matches aaa cba or any other combination.

I'm fairly certain that this is not what you want. You are probably looking for something like this instead:

SELECT substring('http://domainname.com/key4' from 'http://domainname\\.com/\\S{4}')
FROM actions
噩梦成真你也成魔 2024-10-24 14:15:43

这可能是您在这种特定情况下正在寻找的内容,

select substring(substring('long text [http://domainname.com/key4] more text',E'http\:\/\/domainname\.com\/\\S{4}'),E'\\S{4}

如果它是四个字符长,它将提取关键部分。如果您可能也在寻找类似 key456 的内容,那么更通用的匹配

select substring(substring('long text [http://domainname.com/key467] more text',E'http\:\/\/domainname\.com\/key\\d+'),E'key\\d+

可能更合适

);

如果它是四个字符长,它将提取关键部分。如果您可能也在寻找类似 key456 的内容,那么更通用的匹配


可能更合适

);

可能更合适

);

如果它是四个字符长,它将提取关键部分。如果您可能也在寻找类似 key456 的内容,那么更通用的匹配

可能更合适

This might be what you are looking for in this specific case

select substring(substring('long text [http://domainname.com/key4] more text',E'http\:\/\/domainname\.com\/\\S{4}'),E'\\S{4}

which will extract the key part if it is four characters long. If you might also be looking for something like key456 then a more generic match such as

select substring(substring('long text [http://domainname.com/key467] more text',E'http\:\/\/domainname\.com\/key\\d+'),E'key\\d+

may be more appropriate

);

which will extract the key part if it is four characters long. If you might also be looking for something like key456 then a more generic match such as


may be more appropriate

);

may be more appropriate

);

which will extract the key part if it is four characters long. If you might also be looking for something like key456 then a more generic match such as

may be more appropriate

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文