How to use 'regex for website url' in JavaScript

Every line of 'regex for website url' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
35function isGuardianWebsiteUrl(url: string) {
36 return matchHostname(url, [
37 urlConstants.base.mainDomain,
38 urlConstants.base.mainDomainShort
39 ]);
40}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

36function subdomainRegex(baseUrl){
37 var regex;
38
39 baseUrl = _escapeRegExp(baseUrl);
40
41 regex = new RegExp('((?!www)\\b[-\\w\\.]+)\\.' + baseUrl + '(?::)?(?:\d+)?');
42
43 return regex;
44}

Related snippets