re = /(\[\d{3,5} ?x ?\d{3,5}\])/
str = 'Should match:
Hey guys check out this awesome hi-def picture! [320x480]
[F]irst time here plz be nice [6969x6969]
Spaces around the x [123 x 456]
herp derp durr (smallest dimensions that will match) [100x100]
Check out this massive 2.1 jiggapixel image of the entire USA in high detail! (highest dimensions that will match) [99999x99999]
Should not match:
Please go to this spammy site and buy shit so we can steal your credit card (no tag)
Letters in the tag [i234x5678]
Dimension too small [99 x 123]
Dimension too big [100000 x 123]
'
# 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