Skip to content

Instantly share code, notes, and snippets.

@bskaggs
Last active August 29, 2015 14:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bskaggs/553702ad570af953b942 to your computer and use it in GitHub Desktop.
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
#!/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\/"
\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