Skip to content

Instantly share code, notes, and snippets.

@shingonoide
Created May 12, 2011 15:45
Show Gist options
  • Save shingonoide/968791 to your computer and use it in GitHub Desktop.
Save shingonoide/968791 to your computer and use it in GitHub Desktop.
Irb session testing generic regex
ruby-1.8.7-p334 :001 > /<p>.*</p>/
ruby-1.8.7-p334 :002/> /<p>.*<\/p>/
SyntaxError: compile error
(irb):1: unknown regexp option - p
(irb):2: syntax error, unexpected '.'
/<p>.*<\/p>/
^
from (irb):2
ruby-1.8.7-p334 :003 > /<p>.*<\/p>/
=> /<p>.*<\/p>/
ruby-1.8.7-p334 :004 > r = /<p>.*<\/p>/
=> /<p>.*<\/p>/
ruby-1.8.7-p334 :005 > r
=> /<p>.*<\/p>/
ruby-1.8.7-p334 :006 > r.match
ArgumentError: wrong number of arguments (0 for 1)
from (irb):6:in `match'
from (irb):6
ruby-1.8.7-p334 :007 > texto = '<p>blablabla</p>'
=> "<p>blablabla</p>"
ruby-1.8.7-p334 :008 > r.match texto
=> #<MatchData "<p>blablabla</p>">
ruby-1.8.7-p334 :009 > r = /<p>(.*)<\/p>/
=> /<p>(.*)<\/p>/
ruby-1.8.7-p334 :010 > r.match texto
=> #<MatchData "<p>blablabla</p>" 1:"blablabla">
ruby-1.8.7-p334 :011 >
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment