Technology moves fast! ⚡ Don't get left behind.🚶 Subscribe to our mailing list to keep up with latest and greatest in open source projects! 🏆

Subscribe to our mailing list


Make difficult regular expressions easy! Ruby port of the awesome VerbalExpressions repo -

Subscribe to updates I use verbal_expressions

Statistics on verbal_expressions

Number of watchers on Github 546
Number of open issues 5
Average time to close an issue 3 days
Main language Ruby
Average time to merge a PR 1 day
Open pull requests 1+
Closed pull requests 1+
Last commit almost 5 years ago
Repo Created almost 6 years ago
Repo Last Updated about 1 year ago
Size 359 KB
Organization / Authorryan-endacott
Latest Releasev0.1.4
Page Updated
Do you use verbal_expressions? Leave a review!
View open issues (5)
View verbal_expressions activity
View on github
Fresh, new opensource launches 🚀🚀🚀
Trendy new open source projects in your inbox! View examples

Subscribe to our mailing list

Evaluating verbal_expressions for your project? Score Explanation
Commits Score (?)
Issues & PR Score (?)


Build Status Gem Version

Ruby Regular Expressions made easy

VerbalExpressions is a Ruby library that helps to construct difficult regular expressions - ported from the awesome JavaScript VerbalExpressions.

How to get started

Just install with gem install verbal_expressions, then require the library and you're good to go!

require 'verbal_expressions'


Here's a couple of simple examples to give an idea of how VerbalExpressions works:

Testing if we have a valid URL

# Create an example of how to test for correctly formed URLs
tester = do
  find 'http'
  maybe 's'
  find '://'
  maybe 'www.'
  anything_but ' '

# Create an example URL
test_url = ""

# Use it just like a regular Ruby regex:
puts 'Hooray!  It works!' if tester.match(test_url)
puts 'This works too!' if tester =~ test_url

# Print the generated regex:
puts tester.source # => /^(http)(s)?(\:\/\/)(www\.)?([^\ ]*)$/

Replacing strings

# Create a test string
replace_me = "Replace bird with a duck"

# Create an expression that seeks for word "bird"
expression = { find 'bird' }

# Execute the expression like a normal Regexp object
result = replace_me.gsub( expression, "duck" );

puts result # Outputs "Replace duck with a duck"

Regex Capturing

# Grab the number of goals

tester = do
  find 'scored '
  begin_capture 'goals' # Can be named or unnamed

match = tester.match('Jerry scored 5 goals!')
puts match['goals'] # => 5

# Alternative capture syntax

tester = do
  find 'scored '
  capture('goals') { word }

API documentation

I haven't added much documentation to this repo yet, but you can find the documentation for the original JavaScript repo on their wiki. Most of the methods have been ported as of v0.1.0 of the JavaScript repo. Just be sure to use the syntax explained above rather than the dot notation :)


Clone the repo and fork! Pull requests are warmly welcomed!


  • I haven't yet ported the modifier code because Ruby Regexp handles modifiers a little differently.
  • Because or is reserved in Ruby, or is currently aliased to alternatively. Unfortunately, then is also reserved, so you must use find instead. I'm very open to better name ideas :)


Thank you to @jehna for coming up with the awesome original idea!

Bitdeli Badge

verbal_expressions open issues Ask a question     (View All Issues)
  • almost 5 years "Alternatively" gives unexpected behaviour
  • almost 6 years DSL vs. method chaining?
  • almost 6 years 'exactly' instead of 'find' ?
  • almost 6 years Shorter name?
verbal_expressions open pull requests (View All Pulls)
  • Added start/end of string, "hex", modifiers
verbal_expressions list of languages used
Other projects in Ruby