Last active
December 22, 2022 14:04
-
-
Save darkmavis1980/50a4d20a6f9f58b95c10774d5f252ac4 to your computer and use it in GitHub Desktop.
Matches either hubspot domain or hs-sites (sandboxes)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// url => https://regex101.com/r/jhw0wy/1 | |
const regex = /https:\/\/([a-z\.]{4})?([0-9]+.hs-sites|hubspot).com[\/]?/gm; | |
// Alternative syntax using RegExp constructor | |
// const regex = new RegExp('https:\/\/([a-z\.]{4})?([0-9]+.hs-sites|hubspot).com[\/]?', 'gm') | |
const str = `https://hubspot.com/ | |
https://123456.hs-sites.com/ | |
https://google.com`; | |
let m; | |
while ((m = regex.exec(str)) !== null) { | |
// This is necessary to avoid infinite loops with zero-width matches | |
if (m.index === regex.lastIndex) { | |
regex.lastIndex++; | |
} | |
// The result can be accessed through the `m`-variable. | |
m.forEach((match, groupIndex) => { | |
console.log(`Found match, group ${groupIndex}: ${match}`); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment