re = /(?:^|[])] +)(?P<title>\w+)(?: +[[【(]|$)/m
str = '(event) (tag) [group (artist)] title (form) [addition1] [addition2]
(event) [group (artist)] title (form) [addition1]
[event] [group (artist)] title (form) (addition1)
(tag) [group (artist)] title
[group (artist)] title
title
【tag】 [group (artist)] title 【form】
[group (artist)] title
[group] title
[artist] title
(artist) title
'
# 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