From: dblack@... Date: 2006-12-21T05:40:26+09:00 Subject: Re: Regexp Question: Checking for [joe][/joe] pairs Hi Joe -- On Thu, 21 Dec 2006, Joe Peck wrote: > Hey, I've got some text in @x and want there to be at least 1 and at > most 3 [joe][/joe] pairs, each having at least one character between the > beginning [joe] and the ending [/joe]. > > This is what I have now, and it seems to sometimes work, and sometimes > not. > > @x.match(/(\[joe\][\s\d\w]+?\[\/joe\]){1,3}/) require 'test/unit' class JoeTest < Test::Unit::TestCase def setup @re = /(\[joe\][\s\d\w]+?\[\/joe\]){1,3}/ end def test_ok assert("[joe]abc[/joe]".match(@re)) end def test_broken # ??? <--- fill in the blank :-) end end David -- Q. What's a good holiday present for the serious Rails developer? A. RUBY FOR RAILS by David A. Black (http://www.manning.com/black) aka The Ruby book for Rails developers! Q. Where can I get Ruby/Rails on-site training, consulting, coaching? A. Ruby Power and Light, LLC (http://www.rubypal.com)