DEPRECATED
Being replaced by kddnewton/exreg.
RegularExpression
A regular expression engine written in Ruby.
Installation
Add this line to your application's Gemfile:
gem "regular_expression"
And then execute:
$ bundle install
Or install it yourself as:
$ gem install regular_expression
Dependencies
Cranelift
One of the backends that the regular expression compiler can use is cranelift, which is a rust project with Ruby bindings handled by the cranelift_ruby
gem. In order to use the compiler, you'll need to have cargo
installed so that it can compile the rust native extension. On a Mac or Linux you can curl https://sh.rustup.rs -sSf | sh
. For other platforms, searching install cargo can tell you how. Additionally, you'll need your Ruby to have been compiled with the --enable-shared
option.
Capstone
To call #disasm
on the generated machine code, you'll need Capstone installed. On a Mac you can brew install capstone
, or on Ubuntu you can sudo apt-get install libcapstone-dev
. For other platforms, searching install capstone can tell you how.
Graphviz
To call #to_dot
on the syntax tree or the state machines, or run the tests, you'll need Graphviz installed. On a Mac you can brew install graphviz
, or on Ubuntu you can sudo apt-get install graphviz
. For other platforms, searching install graphviz can tell you how.
Usage
To create a regular expression pattern, use:
pattern = RegularExpression::Pattern.new("ab?c")
Patterns can be queried for whether or not they match a test string, as in:
pattern.match?("abc") # => true
pattern.match?("ac") # => true
pattern.match?("ab") # => false
Development
After installing the dependencies checking out the repo, run bundle install
to install dependencies. Then, run bundle exec rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Status
At the moment we support most basic features, but there is a lot of ground left to cover. Some of them are written out in issues, while others are just documented here. Here is the current list as it stands:
Syntax | Status | Issue |
---|---|---|
Character classes | 🛠 | #6 |
Repetition | ✅ | |
Non-greedy repetition | ❌ | |
Capturing | 🛠 | #3 |
Named captures | ✅ | #84 |
Grouping | ✅ | |
Atomic grouping | ❌ | |
Subexpression calls | ❌ | |
Alternation | ✅ | |
Character properties | 🛠 | #8 |
Anchors | 🛠 | #9 |
Assertions | 🛠 | #10 |
Case-insensitive mode | 🛠 | #4 |
Multi-line mode | ❌ | #5 |
Free-spacing mode | ✅ | #11 |
Encoding support | ❌ | #12 |
Backreferences | ❌ |
Benchmarking
To benchmark the current performance on your current version of Ruby, run:
$ bundle exec rake benchmark
Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/kddnewton/regular_expression. For information about how to contribute to the development of this gem, see the CONTRIBUTING.md document.
License
The gem is available as open source under the terms of the MIT License.