postgresql正则表达式和子字符串
我有一个正则表达式 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
{7}
代表之前模式的 7 倍。因此,在本例中,[
和]
之间存在不同的字符。即[abc]{3}
匹配aaa
cba
或任何其他组合。我相当确定这不是您想要的。您可能正在寻找类似的东西:
The
{7}
stands for 7 times the previous pattern. So in this case, the different characters between[
and]
. i.e.[abc]{3}
matchesaaa
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:
这可能是您在这种特定情况下正在寻找的内容,
可能更合适
);如果它是四个字符长,它将提取关键部分。如果您可能也在寻找类似 key456 的内容,那么更通用的匹配
可能更合适
This might be what you are looking for in this specific case
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