Reputation: 293
How can I delete everything that appears after the second bar?
SELECT REGEXP_replace('/admin/home/log', '(/\w+){,2}','');
SELECT REGEXP_replace('/admin/home/out', '(/\w+){,2}','');
SELECT REGEXP_replace('/admin/login', '(/\w+){,2}','');
SELECT REGEXP_replace('/test/login', '(/\w+){,2}','');
SELECT REGEXP_replace('/test/login/file/cam', '(/\w+){,2}','');
Solutions:
/admin/home
/admin/home
/admin/login
/test/login
/test/login
Upvotes: 1
Views: 472
Reputation: 60472
Instead if replacing the remainder you can simply extract everything before a 3rd slash:
SELECT REGEXP_SUBSTR('/admin/home/log', '(/[^/]+){1,2}');
Upvotes: 1
Reputation: 50064
Using regexp_replace()
:
SELECT REGEXP_REPLACE('/admin/home/log/test', '([^/]/[^/]*/).*$', '\1');
Upvotes: 2