re = /(?:^|\n\d+\))[^)(]*(?:\([^)(]*(?:\([^)(]*(?:\([^)(]*(?:\([^)(]*\)[^)(]*)*\)[^)(]*)*\)[^)(]*)*\)[^)(]*)*(?:(?<=\D)\)|\([^)]*$)/
str = 'Текст текст текст. Список:
1) пункт первый
2) пункт второй
3) пункт третий
228) на ркопункт
1337) элитный пункт
Текст (текст (в (скобках) ещё (текст) в) скобках) текст.
1488) наципункт
Скобкодаун тешится)))
Скобкодаун грустит((('
# 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