需要在sql中使用正则表达式解析字符串中的第3个/

时间:2013-10-07 11:35:06

标签: sql regex oracle

当我尝试使用regexp来自以下来源的\|(.*?),1,2提取时,我即将结束,但我需要第3 /只。当我使用\|(.*/){1,3},1,2时,它正在给http://localhost:6148372/content/bdsajf,而我却在结束搜索位置。请帮助我。

U=https://www.abcdf.com/aecb/app/login|http://llcwokhfkdvc.webs.com/sajc-services
U=http://localhost:7438/en.html|http://localhost:6148372/content/bdsajf/en/kjf-LKJf/FJKSF-cbxjs.html

O / P应为#http://llcwokhfkdvc.webs.comhttp://localhost:6148372

由于

3 个答案:

答案 0 :(得分:1)

尝试以下表达式:

\|([^/]*/*[^/]*)

请参阅live demo

答案 1 :(得分:0)

尝试'\|([^/]*/){1,3}'(11i):

SQL> SELECT regexp_substr(txt, '\|(([^/]*/){1,3})', 1, 1, 'i', '1') regexp
  2    FROM DATA;

REGEXP
--------------------------------------------------------------------------------
http://llcwokhfkdvc.webs.com/
http://localhost:6148372/

在10g:

SQL> SELECT ltrim(regexp_substr(txt, '\|([^/]*/){1,3}'), '|') regexp
  2    FROM DATA;

REGEXP
--------------------------------------------------------------------------------
http://llcwokhfkdvc.webs.com/
http://localhost:6148372/

答案 2 :(得分:0)

您可以尝试:

SELECT regexp_substr(t, '\|(http://.*?)/', 1, 1, NULL, 1)
  FROM (
    SELECT
      'U=https://www.abcdf.com/aecb/app/login|http://llcwokhfkdvc.webs.com/sajc-services' AS t
    FROM DUAL
    UNION
    SELECT
      'U=http://localhost:7438/en.html|http://localhost:6148372/content/bdsajf/en/kjf-LKJf/FJKSF-cbxjs.htmlO/P should be # http://llcwokhfkdvc.webs.com and http://localhost:6148372' AS t
    FROM DUAL
);