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 :: js check if element into view 
Javascript :: js find lowest number in array 
Javascript :: how to drawImage on center of canvas 
Javascript :: document ready in jquery 
Javascript :: how to submit using checkbox 
Javascript :: update node .js 
Javascript :: array sum javascript 
Javascript :: header ejs 
Javascript :: how to open browser for upload with click on element in jquery 
Javascript :: jquery onchange 
Javascript :: is email js 
Javascript :: how to remove a class from element with javascript 
Javascript :: javascript base64 encode 
Javascript :: jquery ajax get 
Javascript :: camera helper three js 
Javascript :: js append element to body 
Javascript :: kb to mb javascript 
Javascript :: get all mondays in calendar+js 
Javascript :: javascript fetch api post 
Javascript :: horizontal divider react native 
Javascript :: javascript hwo to return largest value with index 
Javascript :: session storage 
Javascript :: carousel speed bootstrap 
Javascript :: add a route to a buttoin in angular 
Javascript :: expo build apk 
Javascript :: To set the dropdown default value using jquery 
Javascript :: get last day of month javascript 
Javascript :: react cloud foundry nginx 404 
Javascript :: javascript factorial 
Javascript :: push tr in tbody using jquery 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =