更新时间:2022-11-11 23:36:16
对于 Ruby 1.8.7,这可以做到.
For Ruby 1.8.7 this will do it.
url_1 = 'http://www.***.com/watch?v=8WVTOUh53QY&feature=feedf'
url_2 = 'http://www.***.com/user/ForceD3strategy#p/a/u/0/8WVTOUh53QY'
regex = /***.com.*(?:\/|v=)([^&$]+)/
puts url_1.match(regex)[1] # => 8WVTOUh53QY
puts url_2.match(regex)[1] # => 8WVTOUh53QY