从PostgreSQL中的字符串中提取特定单词

时间:2013-05-08 19:44:51

标签: regex string postgresql pattern-matching extract

我正在使用pgadmin版本1.16.1,我需要提取“登录”字样。并且'退出'从 结果列

url

"http:/login-v1.abcd.com/service/abc/integration" 
"http:/xxxxxxxxlogout"
"https:/login-v1.abcd.com/service" 

结果

 url                                                 Action  

"http:/login-v1.abcd.com/service/abc/integration"    login 
 "http:/xxxxxxxxlogout"                              logout
"https:/login-v1.abcd.com/service"                   login

我该怎么做?

1 个答案:

答案 0 :(得分:3)

substring()与正则表达式一起使用:

WITH t(txt) AS (VALUES 
     ('http:/login-v1.abcd.com/service/abc/integration')
    ,('http:/xxxxxxxxlogout')
    ,('https:/login-v1.abcd.com/service')
    )
SELECT txt, substring(txt FROM '(login|logout)') AS action FROM t