Last active
August 29, 2015 14:06
-
-
Save bskaggs/553702ad570af953b942 to your computer and use it in GitHub Desktop.
Create validating regex for tag link urls based on the stackexchange site feed
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
#!/usr/bin/env ruby | |
require 'rss' | |
require 'open-uri' | |
url = 'http://stackexchange.com/feeds/sites' | |
subdomains = [] | |
domains = [] | |
open(url) do |rss| | |
feed = RSS::Parser.parse(rss, do_validate = false) | |
feed.items.each do |item| | |
uri = URI.parse(item.id.content) | |
domain = uri.host | |
if domain =~ /\.stackexchange\.com/ | |
subdomains << $` | |
else | |
domains << domain | |
end | |
end | |
end | |
def escape(domains) | |
"(#{domains.sort.map{ |d| Regexp.escape(d) }.join('|')})" | |
end | |
puts "\\Ahttp://((#{escape(subdomains)}\.stackexchange\.com)|(#{escape(domains)}))\/tags\/" |
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
\Ahttp://(((academia|android|anime|apple|arduino|astronomy|aviation|beer|bicycles|biology|bitcoin|blender|boardgames|bricks|buddhism|chemistry|chess|chinese|christianity|codegolf|codereview|cogsci|cooking|craftcms|crypto|cs|cstheory|datascience|dba|diy|drupal|dsp|earthscience|ebooks|electronics|ell|english|expatriates|expressionengine|fitness|freelancing|french|gamedev|gaming|gardening|genealogy|german|gis|graphicdesign|ham|hermeneutics|hinduism|history|homebrew|islam|italian|japanese|joomla|judaism|linguistics|magento|martialarts|math|matheducators|mathematica|mechanics|meta|moderators|money|movies|music|networkengineering|opendata|outdoors|parenting|patents|pets|philosophy|photo|physics|pm|poker|politics|productivity|programmers|puzzling|quant|raspberrypi|reverseengineering|robotics|rpg|russian|salesforce|scicomp|scifi|security|sharepoint|skeptics|softwarerecs|sound|space|spanish|sports|sqa|startups|stats|sustainability|tex|tor|travel|tridion|unix|ux|video|webapps|webmasters|windowsphone|wordpress|workplace|writers).stackexchange.com)|((askubuntu\.com|mathoverflow\.net|pt\.stackoverflow\.com|serverfault\.com|stackapps\.com|stackoverflow\.com|superuser\.com)))/tags/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment