Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have something as:-

....ttrt .....ddd.dd

I only want to pick following

The possible regex i wrote is


The problem is that its only picking on dd part.

With the latest regex i see following problems:- fgf fgf

....ttrt .....ddd.dd fgf ff fgfgf

.ru fgf

It will stop matching anything after space e.g fgfgs. The regex should work with space and even without space.

share|improve this question
up vote 1 down vote accepted

Maybe try something like this?

share|improve this answer
thanks can u rcplain the role of ?: – asadz Aug 15 '13 at 19:12
@asadz Yes, (?: ... ) is a non-capture group. It... will not be captured into a group ^^; – Jerry Aug 15 '13 at 19:15
There is a slight problem if I add fgf which is space after .pk it will start to match fgf for me i don't want the match to stop well before that. – asadz Aug 15 '13 at 19:51
@asadz I made a bracketing mistake, oops! Try to see if the updated regex works ^^; – Jerry Aug 15 '13 at 19:54
kindly see my updated question. – asadz Aug 15 '13 at 20:54

If I did understand the question awk can do it using:

awk '{split($0,uri,"/");c=split(uri[3],domain,".");
domain[1]=="www"?a=3:a=2; for (i=a;i<=c;i+=1){

A sample usage:

printf "%s\n" '' '' | awk '{split($0,uri,"/");c=split(uri[3],domain,"."); domain[1]=="www"?a=3:a=2; for (i=a;i<=c;i+=1){ printf("%s%s"),domain[i],i==c?"\n":"."}}'


share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .