re = /[[:blank:]]*+(?:[\[\(].*[\]\)][[:blank:]]*+)?(.*?)[[:blank:]\[\(]*+([1-2]\d{3}).*
/mx
str = '2 Fast 2 Furious [2003] [SD]
2 Fast 2 Furious (2003) [SD]
2 Fast 2 Furious ((2003) [SD]
A Goofy Movie (1995) (HD) (720p)
[test]A Goofy Movie (1995) (HD) (720p)
(test) A Goofy Movie (1995) (HD) (720p)
2 Fast 2 Furious 2003
2 Fast 2 Furious 2003
The Lion King 2- Simba\'s Pride (1998) (HD) (1080p)
The.Grand.Budapest.Hotel.2014.1080p.BluRay.x264-BLOW
Another.Earth.2011.LIMITED.720p.BluRay.X264-AMIABLE
The.Green.Mile.1999.720p.BluRay.x264-HDCLASSiCS
The Road 2009 Bluray DTS 720 p - TRiNiTY
Dead Poets Society (1989) 720p Blu-ray x264 DTS MSubs [DDR]
Garden.State.2004.720p.BluRay.X264-AMIABLE
'
subst = '\\1 (\\2) \\3'
result = str.gsub(re, subst)
# Print the result of the substitution
puts result
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