0

I would like to trim a list of urls to first folder

for example:
url.com/folder1/xxx/index.html
url.com/folder2/
url.com/folder3/xxx/yyyy/index.html
url.com/folder4/zzz/aaa/bbb/index.html

Output should look like this:
url.com/folder1/
url.com/folder2/
url.com/folder3/
url.com/folder4/

Any help would be much appreciated. Thanks!

ciprian
  • 3
  • 1
  • What have you tried so far? You don't provide any details about _how_ this should be done, where the Output should go etc,. Your question is tagged [regex[ and [notepad++] but other than that we have no context for your problem. – Aiken Feb 19 '15 at 10:13
  • i tried doing it in scrapebox but it only trims to last folder not first.I have no experience with notepad++ or regex ,searched on google with no luck. – ciprian Feb 19 '15 at 10:49
  • Does this answer your question? [Reference - What does this regex mean?](https://stackoverflow.com/questions/22937618/reference-what-does-this-regex-mean) – AdrianHHH Mar 18 '21 at 16:06

2 Answers2

1

Find what:

^([^/]*/[^/]*/).*

OR

Escape the forward slashes if necessary.

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

Replace with:

\1

DEMO

Avinash Raj
  • 160,498
  • 22
  • 182
  • 229
  • add `hhtp://` at the start in the replacement string. see https://regex101.com/r/aS7zX3/3 – Avinash Raj Feb 19 '15 at 10:48
  • Sorry i'm new here ...i just signed up so bare with me :) ...what i ment to say is that if the originial urls haves http:// in it ...so (http://url.com/folder1/zzz/index.html) -> (http://url.com/folder1/) .I couldn't add http:// in my original post because i'm a new user i cannot post more then 1 or 2 urls. – ciprian Feb 19 '15 at 11:13
1

Find: ^.*?\/.*?\/\K.*$

Try this.Replace by empty string.See demo.

https://regex101.com/r/mS3tQ7/14

\K resets the starting point of the reported match. Any previously consumed characters are no longer included in the final match

vks
  • 63,206
  • 9
  • 78
  • 110