re = /(\&|\?)(id=\d+)/
str = '//detail.tmall.com/item.htm?abtest=&pvid=42b3a520-35a1-47f8-abe8-572bef4a430f&pos=1&abbucket=&acm=03054.1003.1.2768562&id=604432657613&scm=1007.16862.95220.23864_0_0&utparam=%7B%22x_hestia_source%22%3A%2223864%22%2C%22x_object_type%22%3A%22item%22%2C%22x_mt%22%3A0%2C%22x_src%22%3A%2223864%22%2C%22x_pos%22%3A1%2C%22x_pvid%22%3A%2242b3a520-35a1-47f8-abe8-572bef4a430f%22%2C%22x_object_id%22%3A604432657613%7D'
# Print the match result
str.match(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