Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 588769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:21:13+00:00 2026-05-13T15:21:13+00:00

So I want to match just the domain from ether: http://www.google.com/test/ http://google.com/test/ http://google.net/test/ Output

  • 0

So I want to match just the domain from ether:

http://www.google.com/test/
http://google.com/test/
http://google.net/test/

Output should be for all 3: google

I got this code working for just .com

echo "http://www.google.com/test/" | sed -n "s/.*www\.\(.*\)\.com.*$/\1/p"
Output: 'google'

Then I thought it would be as simple as doing say (com|net) but that doesn’t seem to be true:

echo "http://www.google.com/test/" | sed -n "s/.*www\.\(.*\)\.(com|net).*$/\1/p"
Output: '' (nothing)

I was going to use a similar method to get rid of the “www” but it seems im doing something wrong… (does it not work with regex outside the \( \) …)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T15:21:13+00:00Added an answer on May 13, 2026 at 3:21 pm

    This will output “google” in all cases:

    sed -n "s|http://\(.*\.\)*\(.*\)\..*|\2|p"
    

    Edit:

    This version will handle URLs like “‘http://google.com.cn/test” and “http://www.google.co.uk/” as well as the ones in the original question:

    sed -nr "s|http://(www\.)?([^.]*)\.(.*\.?)*|\2|p"
    

    This version will handle cases that don’t include “http://” (plus the others):

    sed -nr "s|(http://)?(www\.)?([^.]*)\.(.*\.?)*|\3|p"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to match all lines that have any uppercase characters in them but
I want to match links like <a href=mailto:my@email.com>foo</a> , but this doesn't work only
I want to match just the folder name that a file is in, eg:
I want to know how to match just the 1st character occurrence using regex
I want to match and assign to a variable in just one line: my
Example: This is just\na simple sentence . I want to match every character between
I want to match words that contain special characters or that begin with 'http://'
I'm studying the re module of Erlang, and I just want to match an
I 'borrowed' a regex from this website : http://daringfireball.net/2010/07/improved_regex_for_matching_urls that is almost complete but
I'm using this function: preg_match_all('/((\d{9})\.html)/s', $content, $results); It works fine but i just want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.