Last active
February 2, 2023 07:45
-
-
Save pernydev/1d5ed26ab8dcdd8d4840aee114b1cce7 to your computer and use it in GitHub Desktop.
Link filter for OpenAI Discord (In JavaScript)
This file contains hidden or 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
| function getDomainsFromString(stringWithUrls) { | |
| const whitelist = ["openai.com", "stackoverflow.com"]; | |
| const urlRegex = /https?:\/\/(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+/g; | |
| const urls = stringWithUrls.match(urlRegex); | |
| const domains = urls.map(url => { | |
| const domainRegex = /(?<domain>[a-zA-Z0-9][a-zA-Z0-9-]{1,61}[a-zA-Z0-9]\.[a-zA-Z]{2,})/; | |
| const domain = url.match(domainRegex).groups.domain; | |
| return domain; | |
| }); | |
| const filteredDomains = domains.filter(domain => whitelist.includes(domain)); | |
| return filteredDomains; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment