Skip to content

Instantly share code, notes, and snippets.

@emrox
Forked from rubiii/pattern.xml
Created January 21, 2012 20:53
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 emrox/1653969 to your computer and use it in GitHub Desktop.
Save emrox/1653969 to your computer and use it in GitHub Desktop.
reuse xml schema pattern via nokogiri
<xsd:pattern xmlns:xsd="http://www.w3.org/2001/XMLSchema" value="\d{3}-[A-Z]{2}"/>
require "nokogiri"
xml = File.read("pattern.xml")
node = Nokogiri.XML(xml).root
/#{node["value"]}/.match("123-AB")
# => #<MatchData "123-AB">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment