/regin

Ruby Regexp Introspection

Primary LanguageRubyMIT LicenseMIT

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">