Flowdock

A Regexp holds a regular expression, used to match a pattern against strings. Regexps are created using the /…/ and %r{…} literals, and by the Regexp::new constructor.

Constants

MULTILINE = INT2FIX(ONIG_OPTION_MULTILINE)

EXTENDED = INT2FIX(ONIG_OPTION_EXTEND)

IGNORECASE = INT2FIX(ONIG_OPTION_IGNORECASE)

Attributes

Show files where this class is defined (3 files)
Register or log in to add new notes.
February 10, 2009
3 thanks

Cheat Sheet

I have written a short introduction and a colorful cheat sheet for Perl Compatible Regular Expressions (PCRE) as used by Ruby’s Regexp class:

http://www.bitcetera.com/en/techblog/2008/04/01/regex-in-a-nutshell/

December 3, 2009 - (v1_8_6_287 - v1_8_7_72)
0 thanks

Testing Regular Expressions?

Writing regular expressions is never easy. You may use http://rubular.com to test and optimize your regular expressions.

March 8, 2010
0 thanks

Eagerness

Check out this simple example:

"Hello Ruby friend".sub(/^(.*)e/,  'X')  # => "Xnd"
"Hello Ruby friend".sub(/^(.*?)e/, 'X')  # => "Xllo Ruby friend"

The question mark turns the dotstar into non-eager mode which means it will halt on the first subsequent “e” rather than the last one. This comes in handy e.g. for Cucumber step definitions.

Okay, but not really nice:

/^I am using rvm "([^\"]*)" with gemset "(.*)"$/

Much more readable and consistent equivalent to the above:

/^I am using rvm "(.*?)" with gemset "(.*?)"$/