Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Ruby Regexp Introspection

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 benchmark
Octocat-spinner-32 lib
Octocat-spinner-32 spec
Octocat-spinner-32 LICENSE
Octocat-spinner-32 README.rdoc
Octocat-spinner-32 Rakefile
Octocat-spinner-32 regin.gemspec
README.rdoc

Regin

Regin allows you to introspect on Ruby Regexps.

Powered by an over the top regexp syntax parser written in racc/rexical.

Examples

Determine if a Regexp could be treated as a literal String

Regin.parse(/foo/).literal? # => true
Regin.parse(/ba./).literal? # => false

Determine whether a character could match a part of a Regexp

Regin.parse(/foo\/bar/).include?("/")    # => true
Regin.parse(/foo.bar/).include?("/")     # => true
Regin.parse(/foo[a-z]bar/).include?("/") # => false

Extract a substring of a Regexp

Regin.parse(/foobar/)[3..6] => #<Expression "bar">
Regin.parse(/fo{2}[bB]ar/)[2..5] => #<Expression "[bB]ar">
Something went wrong with that request. Please try again.