Regular Expressions on Strings
A regular expression is a set of special characters that creates a search pattern. It is used to match and manipulate strings of text.
Here is a simple example:
sentence = 'The angry purple elephant leaped over the scared lion.'
result = sentence.match(/angry (\w+) elephant/)
result[0] # "angry purple elephant"
result[1] # "purple"
I recommend Rubular when you are trying to figure out a regular expression and can’t get it. The live matching function will show you what your expression is matching as you type it.