Project

urlmatch

0.01
No commit activity in last 3 years
No release in over 3 years
Verify URLs confirm to expected patterns. Ruby port of Jesse Pollak's Urlmatch
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

~> 1.11
~> 10.0
~> 3.0
 Project Readme

Gem Version

urlmatch - fnmatch for the web

This is a Ruby port of Jesse Pollak's Python urlmatch.

Use urlmatch to verify that URLs conform to certain patterns. The library and match patterns are based heavily on the Google Chrome Extension match patterns.

Usage

require 'urlmatch'

match_pattern = 'http://*.example.com/*'

Urlmatch.urlmatch(match_pattern, 'http://subdomain.example.com/') # true
Urlmatch.urlmatch(match_pattern, 'http://sub.subdomain.example.com/') # true

Urlmatch.urlmatch(match_pattern, 'https://example.com/') # false
Urlmatch.urlmatch(match_pattern, 'http://bad.com/') # false

Match pattern syntax

The basic match pattern syntax is simple:

<url-pattern> := <scheme>://<host><path>
<scheme> := '*' | 'http' | 'https'
<host> := '*' | '*.' <any char except '/' and '*'>+
<path> := '/' <any chars>

Examples

  • http://*/* - matches any URL that uses the http scheme
  • https://*/* - matches any URL that uses the https scheme
  • http://*/test* - matches any URL that uses the http scheme and has a path that starts with test
  • *://test.com/* - matches any url with the domain test.com
  • http://*.test.com - matches test.com and any subdomain of test.com
  • http://test.com/foo/bar.html - matches the exact URL

Bugs

If you find an issue, let me know in the issues section!