re = /(\[QUOTE[^][]*\]
(?:[^][]++|(?1))++
\[\/QUOTE\])
\Z/xm
str = 'Here is the example post text
[QUOTE]
This is an appropriate quote
[/QUOTE]
Here is more post content
Here is the example post text
[QUOTE]
This is an appropriate quote
[/QUOTE]
Here is more post content
[QUOTE]
This is an unnecessary quote, as it\'s below all of the post text
[QUOTE]
Here\'s an unnecessary nested quote, just to confuse things.
[/QUOTE]
[/QUOTE]'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html