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 :: nextjs global scss variables 
Javascript :: dom element set id 
Javascript :: how to get value of html element in javascript 
Javascript :: date regex format 
Javascript :: get top window url from iframe 
Javascript :: nodejs redis setex 
Javascript :: js add text after div 
Javascript :: js get time 
Javascript :: quasar change port 
Javascript :: axios fetch 
Javascript :: javascript creeate utc date 
Javascript :: javascript onclick button 
Javascript :: get first duv with jquery 
Javascript :: how to set emmet for jsx in visual studio code 
Javascript :: Capitalize the first letter of string using JavaScript 
Javascript :: javascript is null 
Javascript :: momentjs format date 
Javascript :: sort array object 
Javascript :: js largura da tela 
Javascript :: tailwind config for nextjs 
Javascript :: string normalize javascript 
Javascript :: javascript convert string with square brackets to array 
Javascript :: set 404 handling via express in node 
Javascript :: reverse string with recursion 
Javascript :: sort arrays according to first array js 
Javascript :: js date in two weeks 
Javascript :: determine if touch screen js 
Javascript :: node js response header 
Javascript :: how to delete duplicate elements in an array in javascript 
Javascript :: javascript array.find 
ADD CONTENT
Topic
Content
Source link
Name
1+9 =