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}/) > > -- > Posted via http://www.ruby-forum.com/. @x = "[joe] [/joe] [joe][/joe] [joe] foo [/joe]" count = @x.scan(/\[joe\](.*?)\[\/joe\]/m).flatten. reject{|s| ""==s}.size p count