Question: I'm trying to use sed to clean up lines of URLs to extract just the domain.

So from:

```
http://www.suepearson.co.uk/product/174/71/3816/

```

I want:

```
http://www.suepearson.co.uk/

```

(either with or without the trailing slash, it doesn't matter)

I have tried:

```
 sed 's|\(http:\/\/.*?\/\).*|\1|'

```

and (escaping the non-greedy quantifier)

```
sed 's|\(http:\/\/.*\?\/\).*|\1|'

```

but I can not seem to get the non-greedy quantifier (`?`) to work, so it always ends up matching the whole string.

Answer: 
Non-greedy solution for more than a single character
----------------------------------------------------

This thread is really old but I assume people still needs it.
Lets say you want to kill everything till the very first occurrence of `HELLO`. You cannot say `[^HELLO]`...

So a nice solution involves two steps, assuming that you can spare a unique word that you are not expecting in the input, say `top_sekrit`.

In this case we can:

```
s/HELLO/top_sekrit/     #will only replace the very first occurrence
s/.*top_sekrit//        #kill everything till end of the first HELLO

```

Of course, with a simpler input you could use a smaller word, or maybe even a single character.

HTH!
I realize this is an old entry, but someone may find it useful.
As the full domain name may not exceed a total length of 253 characters replace .\* with .\{1, 255\}