Skip to content

Verify URLs conform to expected patterns. Ruby port of Jesse Pollak's Urlmatch

License

Notifications You must be signed in to change notification settings

hjheath/ruby_urlmatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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!

About

Verify URLs conform to expected patterns. Ruby port of Jesse Pollak's Urlmatch

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages