Created
February 1, 2016 15:10
-
-
Save ajaegers/2ed0ddf410ec1a762387 to your computer and use it in GitHub Desktop.
Regex to match a TLD domain
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
/** | |
* Simple regex to match domain even with new tlds and xn-- (internationnal domain names) | |
* @link tld list from http://data.iana.org/TLD/tlds-alpha-by-domain.txt sorted by extension length | |
*/ | |
var re = /(([a-z0-9-_\.]*)\.([a-z0-9-_]+)\.(XN--VERMGENSBERATUNG-PWB|XN--VERMGENSBERATER-CTB|XN--CLCHC0EA0B2G2A9GCD|TRAVELERSINSURANCE|XN--MGBERP4A5D4AR|XN--XKC2DL3A5EE0H|XN--XKC2AL3HYE2A|XN--KCRX77D1X4A|XN--MGBC0A9AZCG|SANDVIKCOROMANT|XN--I1B6B1A6A2E|XN--NQV7FS00EMA|XN--MGBA3A4F16A|XN--LGBBAT1AD8J|XN--MGBX4CD0AB|XN--MGBA3A3EJT|XN--FIQ228C5HS|XN--MGBBH1A71E|XN--B4W605FERD|XN--MGBAAM7A8H|XN--MGBAYH7GPA|XN--MGBB9FBPOB|XN--JLQ61U9W7B|CANCERRESEARCH|WEATHERCHANNEL|XN--6QQ986B3XL|XN--YGBI2AMMX|INTERNATIONAL|XN--FZC2C9E2C|LIFEINSURANCE|SPREADBETTING|XN--YFRO4I67O|XN--ECKVDTC9D|XN--FPCRJ9C3D|XN--MGBT3DHD|XN--QCKA1PMC|XN--3E0B707E|XN--MK1BU44C|XN--80ASEHDB|VERSICHERUNG|XN--NGBC5AZD|XN--NGBE9E0A|CONSTRUCTION|XN--OGBPF8FL|PAMPEREDCHEF|SCHOLARSHIPS|XN--MGB9AWBF|XN--MGBAB2BD|XN--MGBPL2FH|XN--80ADXHKS|XN--42C2D9A|XN--G2XX48C|XN--KPRW13D|XN--ZFR164B|XN--CZR694B|XN--KPRY57D|REDUMBRELLA|XN--EFVY88H|CREDITUNION|XN--3DS443G|LAMBORGHINI|XN--GECRJ9C|BRIDGESTONE|XN--80AO21A|BARCLAYCARD|XN--H2BRJ9C|XN--T60B56A|XN--SES554G|XN--3BST00M|XN--1QQW23A|XN--HXT814E|XN--6FRZ82G|XN--11B4C3D|XN--S9BRJ9C|XN--RHQV96G|XN--D1ACJ3B|XN--IMR513N|XN--Q9JYB4C|XN--MGBTX2B|PRODUCTIONS|XN--FJQ720A|XN--FLW351E|INVESTMENTS|XN--J6W193G|XN--XHQ521B|XN--55QW42G|PLAYSTATION|WILLIAMHILL|PHOTOGRAPHY|CONTRACTORS|ACCOUNTANTS|MOTORCYCLES|XN--VUQ861B|XN--PGBS0DH|XN--ESTV75G|XN--PBT977C|ENTERPRISES|XN--NYQY26A|ENGINEERING|BLACKFRIDAY|XN--45BRJ9C|XN--KPU716F|VOLKSWAGEN|VISTAPRINT|ACCOUNTANT|TELEFONICA|XN--O3CW4H|TECHNOLOGY|TATAMOTORS|XN--FIQ64B|XN--FIQS8S|XN--FIQZ9S|XN--CZRU2D|XN--PSSY2U|XN--CZRS0T|XN--CG4BKI|IMMOBILIEN|XN--C2BR7G|INDUSTRIES|APARTMENTS|XN--IO0A7I|ASSOCIATES|FOUNDATION|XN--9ET52U|CONSULTING|XN--9DBQ2A|XN--90A3AC|XN--KPUT3I|XN--80ASWG|CREDITCARD|XN--Y9A3AQ|XN--55QX5D|CUISINELLA|XN--MXTQ1M|EUROVISION|XN--4GBRIM|PROPERTIES|XN--WGBL6A|XN--WGBH1C|VLAANDEREN|RESTAURANT|XN--45Q11C|MANAGEMENT|REPUBLICAN|BNPPARIBAS|XN--UNUP4Y|XN--3PXU8K|BOEHRINGER|UNIVERSITY|XN--30RR7Y|PROTECTION|HEALTHCARE|SCHAEFFLER|CHRISTMAS|LANDROVER|LANCASTER|XN--TCKWE|LIFESTYLE|EDUCATION|BLOOMBERG|MARKETING|XN--VHQUV|EQUIPMENT|MELBOURNE|XN--L1ACC|ACCENTURE|FAIRWINDS|BARCELONA|TRAVELERS|MICROSOFT|XN--90AIS|FINANCIAL|FIRESTONE|DIRECTORY|FRESENIUS|FURNITURE|XN--C1AVG|SOLUTIONS|XN--J1AMH|STATEFARM|XN--J1AEF|INSURANCE|AQUARELLE|INSTITUTE|COMMUNITY|YODOBASHI|ANALYTICS|AMSTERDAM|STOCKHOLM|XN--NQV7F|ALLFINANZ|GOLDPOINT|XN--D1ALF|HOMEDEPOT|XN--P1ACF|XN--FHBEI|MONTBLANC|VACATIONS|DISCOUNT|PLUMBING|DIAMONDS|LIGHTING|BUSINESS|FIRMDALE|ISTANBUL|SECURITY|SERVICES|DELOITTE|FEEDBACK|ATTORNEY|FOOTBALL|PHARMACY|PARTNERS|PROPERTY|MORTGAGE|BROADWAY|SOFTBANK|BRADESCO|IPIRANGA|SOFTWARE|ENGINEER|MARRIOTT|BUDAPEST|DOWNLOAD|SAARLAND|COMPUTER|XN--QXAM|DEMOCRAT|STCGROUP|MEMORIAL|VENTURES|PICTURES|INFINITI|COMMBANK|CATERING|MOVISTAR|VERISIGN|XN--NODE|EVERBANK|EXCHANGE|SUPPLIES|CAPETOWN|BOUTIQUE|BARGAINS|XN--P1AI|BUILDERS|YOKOHAMA|AIRFORCE|SYMANTEC|GRAINGER|GRAPHICS|BARCLAYS|CLOTHING|CLINIQUE|MUTUELLE|HOLDINGS|CLEANING|REDSTONE|CITYEATS|CIPRIANI|DELIVERY|HELSINKI|FLSMIDTH|BRUSSELS|TRAINING|REVIEWS|COMPANY|COMPARE|SHIKSHA|TRADING|THEATER|TIFFANY|ABOGADO|KITCHEN|CONTACT|CAPITAL|COOKING|EXPOSED|EXPRESS|WHOSWHO|CARAVAN|CORSICA|COUNTRY|COUPONS|COURSES|ANDROID|FASHION|JEWELRY|SYSTEMS|FERRERO|ZUERICH|CAREERS|CRICKET|FINANCE|WINDOWS|CRUISES|YOUTUBE|CARTIER|FISHING|FITNESS|PHILIPS|RENTALS|FLIGHTS|FLORIST|FLOWERS|SCIENCE|STATOIL|THEATRE|RECIPES|ISELECT|PANERAI|FORSALE|REALTOR|MARKETS|YAMAXUN|SURGERY|FROGANS|BAUHAUS|LINCOLN|KOMATSU|LIMITED|GALLERY|CHANNEL|ORGANIC|OKINAWA|SCHWARZ|STARHUB|LIAISON|TICKETS|GENTING|SPIEGEL|DENTIST|LECLERC|BROTHER|ALIBABA|NEUSTAR|DIGITAL|LATROBE|NETWORK|NETBANK|WANGGOU|SCHMIDT|SUPPORT|BENTLEY|LASALLE|LANXESS|HYUNDAI|DOMAINS|WATCHES|BUGATTI|HOTMAIL|WEATHER|TEMASEK|LACAIXA|ACADEMY|STORAGE|HOTELES|HOSTING|AUCTION|HOLIDAY|WEBSITE|CLUBMED|TOSHIBA|SANDVIK|SINGLES|WEDDING|GUITARS|SAMSUNG|SHRIRAM|COLLEGE|HAMBURG|HANGOUT|HITACHI|COLOGNE|REXROTH|ORIGINS|HEALTH|HIPHOP|TIENDA|HOCKEY|TENNIS|TATTOO|TAOBAO|TAIPEI|AGENCY|SYDNEY|SWATCH|GRATIS|GOOGLE|SUZUKI|ABBOTT|AIRTEL|ALIPAY|SUPPLY|GLOBAL|ALSACE|GIVING|STUDIO|YANDEX|INSURE|GARDEN|FUTBOL|ARAMCO|YACHTS|SOCIAL|SOCCER|JAGUAR|TOYOTA|JOBURG|FAMILY|JUEGOS|KAUFEN|AUTHOR|EXPERT|KINDER|EVENTS|ESTATE|XPERIA|SELECT|ENERGY|EMERCK|TRAVEL|BAYERN|SCHULE|SCHOOL|DURBAN|BERLIN|SANOFI|BHARTI|DOOSAN|DIRECT|LAWYER|DESIGN|SAKURA|SAFETY|RYUKYU|DENTAL|ROCHER|DEGREE|REVIEW|DEALER|REPORT|LIVING|REPAIR|DATSUN|REISEN|LONDON|REALTY|BOSTIK|RACING|QUEBEC|LUXURY|BROKER|CAMERA|MADRID|MAISON|MAKEUP|DATING|VIAJES|MARKET|CAREER|PICTET|PIAGET|PHYSIO|PHOTOS|VILLAS|CREDIT|MOBILY|MONASH|CASINO|CONDOS|MORMON|COMSEC|MOSCOW|COFFEE|CENTER|VIRGIN|OTSUKA|CHANEL|WEBCAM|ORANGE|MUSEUM|CLINIC|ORACLE|CLAIMS|ONLINE|WALTER|VISION|NAGOYA|OFFICE|VOYAGE|HERMES|CHROME|CIRCLE|NOWRUZ|VOTING|NORTON|CHURCH|NISSAN|ACTIVE|SALON|NINJA|NIKON|NEXUS|CISCO|LEASE|CHLOE|VISTA|WALES|CHEAP|NADEX|OMEGA|WATCH|CLICK|CLOUD|WEBER|OSAKA|COACH|CODES|MOVIE|PARIS|MONEY|PARTS|PARTY|MIAMI|VIDEO|PHOTO|CROWN|CYMRU|MEDIA|DABUR|DANCE|PIZZA|MANGO|PLACE|CARDS|CANON|POKER|WORKS|PRAXI|PRESS|PROMO|BUILD|VEGAS|WORLD|LUPIN|XEROX|LOTTO|BOSCH|LOTTE|BOOTS|REHAB|REISE|LOANS|BOATS|LIXIL|LINDE|BLACK|DEALS|BINGO|RICOH|DELTA|ROCKS|RODEO|TUSHU|LEXUS|LEGAL|VODKA|NOKIA|BIBLE|DRIVE|LAMER|TRUST|DUBAI|BEATS|EARTH|KYOTO|EDEKA|EMAIL|BAIDU|EPSON|SENER|AZURE|SEVEN|KOELN|AUTOS|SHARP|SHELL|SHOES|FAITH|TRADE|AUDIO|JETZT|SKYPE|TOURS|SMILE|TORAY|FINAL|FOREX|IRISH|SOLAR|SPACE|TOOLS|STADA|ARCHI|FORUM|GIFTS|APPLE|AMICA|GIVES|STUDY|STYLE|TOKYO|SUCKS|GLASS|IINET|GLOBO|GMAIL|HOUSE|TODAY|GREEN|SWISS|TMALL|TIROL|HORSE|HONDA|TIRES|HOMES|GRIPE|TATAR|GROUP|ADULT|GUCCI|GUIDE|ACTOR|CITIC|VIVA|MODA|DOCS|FILM|PROD|CALL|PROF|IMMO|CAFE|BUZZ|DIET|FAST|VANA|FARM|QPON|DESI|FANS|JOBS|READ|LGBT|CLUB|GOOG|BOOK|BOND|HSBC|MTPC|LIDL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sub.test.it, sub.test.co.uk, www.dfsdf.com, www.test.dfsdf.com, file-notld.json, file-notld.txt'; | |
console.log(str.match(re)); // return complete domain, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment