Skip to content

Instantly share code, notes, and snippets.

@geemus
Created March 31, 2009 20:00
Show Gist options
  • Save geemus/88377 to your computer and use it in GitHub Desktop.
Save geemus/88377 to your computer and use it in GitHub Desktop.
# Optimized regex for finding urls
# Top level domain list from: http://data.iana.org/TLD/tlds-alpha-by-domain.txt
/(?:^|\s)(?:http[s]?:\/\/)?(?:www\.)?([-a-zA-Z_\.]*\.(?:a(?:[cdfgilmnoqtuwxz]|e(?:ro)?|r(?:pa)?|s(?:ia)?)|b(?:[abdefghjmnorstvwyz]|i(?:z)?)|c(?:[cdfghiklmnruvxyz]|a(?:t)?|o(?:m|op)?)|d(?:[ejkmoz])|e(?:[cegrstu]|du)|f(?:[ijkmor])|g(?:[abdefghilmnpqrstuwy]|ov)|h(?:[kmnrtu])|i(?:[delmoqrst]|n(?:fo|t)?)|j(?:[emp]|o(?:bs)?)|k(?:[eghimnprwyz])|l(?:[abcikrstuvy])|m(?:[acdeghklmnpqrstvwxyz]|il|o(?:bi)?|u(?:seum)?)|n(?:[cfgilopruz]|a(?:me)?|e(?:t)?)|o(?:m|rg)|p(?:[aefghklmnstwy]|r(?:o)?)|q(?:a)|r(?:[eosuw])|s(?:[abcdeghijklmnortuvyz])|t(?:[cdfghjklmnoptvwz]|el|r(?:avel)?)|u(?:[agksyz])|v(?:[aceginu])|w(?:[fs])|xn--(?:0zwm56d|11b5bs3a9aj6g|80akhbyknj4f|9t4b11yi5a|deba0ad|g6w251d|hgbk6aj7f53bba|hlcj6aya9esc7a|jxalpdlp|kgbechtv|zckzah)|y(?:[etu])|z(?:[amw]))(?:[\/]?|(?:[\/]??[-a-zA-Z_\.\/?=&]*)))(?:[,\!\.\?])?(?:\s|$)/iu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment