简体   繁体   中英

need to parse up to 3rd / in a string by using regexp in sql

when i am trying extract through regexp from the below source by using \\|(.*?),1,2 this, i am getting up to end but i need to 3rd / only. when i use \\|(.*/){1,3},1,2 it is giving http://localhost:6148372/content/bdsajf and i am stuck up at ending search position. please help me on this.

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 should be # http://llcwokhfkdvc.webs.com and http://localhost:6148372

Thanks

Try the following expression:

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

See live demo

Try '\\|([^/]*/){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/

In 10g:

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

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

You can try:

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
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM