M
M
Mesuti2020-04-29 17:06:10
JavaScript
Mesuti, 2020-04-29 17:06:10

What regular expression to clear domains from a tree?

Hey!
How can a regular expression for clearing domains from a directory tree look like, leaving the protocol and domain?
I do a bulk Find \\ Replace

For example, you need to leave only https:://site.ruorhttp://en.site.ru

https://site.ru
http://site.ru
http://site.xyz/bla
https://site.com/blabla/test
https://en.site.com/blabla/test
site.ru/blabla/test/test2


Sandbox

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry, 2020-04-29
@Mesuti

<script>

var s_ar=new Array (
 "https://site.ru",
 "http://site.ru",
 "http://site.xyz/bla",
 "https://site.com/blabla/test",
 "https://en.site.com/blabla/test",
 "site.ru/blabla/test/test2"
);

var x_ar=new Array ();
var i, l=s_ar.length;
var r="";
for (i=0; i<l; i++)
{
 x_ar=s_ar [i].split(/\//);
 if (s_ar [i].indexOf ("://")!=-1)
  r+=x_ar [0]+"/"+x_ar [1]+"/"+x_ar [2]+"\n";
 else
  r+=x_ar [0]+"\n";
}

alert (r);

</script>

V
vreitech, 2020-04-29
@fzfx

https://regex101.com/r/Nd19ry/3
or
https://regex101.com/r/Nd19ry/4

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question