Regexp_replace for oracle for https replacement not working

Does anyone know why RegExp runs on simulators but not really in oracle?

replace // with / except with https: //

SELECT regexp_replace (url_link,'(?<!https:)\/\/','\/'), url_link
FROM URL_TABLE;

changes

https://pet/green//car/plane//garden

to

https://pate/gren/car/plane/gardn

Thank you

+4
source share
2 answers

Use a list of non-Colon characters for the character preceding //the REGEXPR_REPLACE pattern line

This is the same as Littlefoot's solution, except that we do not replace the first with the //previous one :.

We simply point out that we do not want a match for an asymmetric character list [^:], and then encapsulate it in a group of characters (put this in the parenthesis).

\1, .

SCOTT@db>SELECT
  2      regexp_replace('https://pet/green//car/plane//garden','([^:])//','\1/')  http_url
  3  FROM
  4      dual;

http_url                                 
------------------------------------
https://pet/green/car/plane/garden

, , Oracle () () lookbehind.

Vim:

\(https:\|http:\)\@<!= lookbehind "https:" "http:"

\/\/=

//,

enter image description here

+6

, ():

SQL> with test as (select 'https://pet/green//car/plane//garden' url from dual)
  2  --
  3  select
  4    regexp_replace(url, '//', '/', 8) res1,
  5    regexp_replace(url, '//', '/', instr(url, '//') + 1) res2
  6  from test;

RES1                               RES2
---------------------------------- ----------------------------------
https://pet/green/car/plane/garden https://pet/green/car/plane/garden

SQL>

[ Gary_W RES2]

+4

Source: https://habr.com/ru/post/1694059/


All Articles