Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

regex get only domain name from url

^(?:https?://)?(?:[^@/
]+@)?(?:www.)?([^:/?
]+)

/// Extract result only domain name and subdomain

https://play.google.com/store/apps/details?id=com.skgames.trafficracer%22
play.google.com

http://mplay.google.co.in/sadfask/asdkfals?dk=10
mplay.google.co.in

http://lplay.google.co.in/sadfask/asdkfals?dk=10

http://play.google.co.in/sadfask/asdkfals?dk=10
play.google.co.in

http://tplay.google.co.in/sadfask/asdkfals?dk=10
tplay.google.co.in

http://www.google.co.in/sadfask/asdkfals?dk=10
google.co.in

www.google.co.in/sadfask/asdkfals?dk=10
google.co.in

http://user:pass@google.com/?a=b#asdd
google.com

https://www.compzets.com?sd=10
compzets.com

www.compzets.com?asd=10
compzets.com



Comment

regx get only domain name from url

function domain_from_url(url) {
    var result
    var match
    if (match = url.match(/^(?:https?://)?(?:[^@
]+@)?(?:www.)?([^:/
?=]+)/im)) {
        result = match[1]
        if (match = result.match(/^[^.]+.(.+..+)$/)) {
            result = match[1]
        }
    }
    return result
}

console.log(domain_from_url("www.google.com"))
console.log(domain_from_url("yahoo.com/something"))
console.log(domain_from_url("freds.meatmarket.co.uk?someparameter"))
console.log(domain_from_url("josh.meatmarket.co.uk/asldf/asdf"))

// google.com
// yahoo.com
// meatmarket.co.uk
// meatmarket.co.uk
Comment

get domain name with regex

const urls = [
  'www.abc.au.uk',
  'https://github.com',
  'http://github.ca',
  'https://www.google.ru',
  'http://www.google.co.uk',
  'www.yandex.com',
  'yandex.ru',
  'yandex',
  'devmaster.auxitaplatform.com',
]

urls.forEach(url => console.log(url.replace(/.+//|www.|..+/g, '')))
Comment

PREVIOUS NEXT
Code Example
Javascript :: open a new tab when clicking on a link react 
Javascript :: jquery post upload file 
Javascript :: trigger click jquery 
Javascript :: TypeError: date.getHours is not a function 
Javascript :: javascript check if objects are equal 
Javascript :: activate es6 module node 
Javascript :: Find channel discord js 
Javascript :: javascript alerter 
Javascript :: groupby javascript by instances 
Javascript :: Unhandled rejection TypeError: Article.findById is not a function sequelize 
Javascript :: reference body js 
Javascript :: execute code after page load javascript 
Javascript :: how to empty an element in javascript 
Javascript :: js replace broken image 
Javascript :: delete empty values from object js 
Javascript :: add element to body javascript 
Javascript :: useHistory is not exported form react-router-dom 
Javascript :: node list files in directory 
Javascript :: angular get current time 
Javascript :: how to execute javascript after c# function execute 
Javascript :: dispatch keydown event javascript 
Javascript :: Access-Control-Allow-Origin 
Javascript :: laravel jquery ajax post csrf 
Javascript :: material ui icon color 
Javascript :: check empty object 
Javascript :: replace globally in javascript 
Javascript :: remove disable attr jquery 
Javascript :: Playing sound in Vue.js 
Javascript :: js replace non a-z 
Javascript :: regex valid jwt 
ADD CONTENT
Topic
Content
Source link
Name
3+8 =