Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个类似于此的字符串:
|image: http://product_image.png |product: http://product_url.html
因此,模式是 |image: URL |product: URL
如何在 Ruby 中找到这两个 URL?
试试这个正则表达式:
regex = /image: (.+) \|product: (.+)/ result = regex.match("|image: http://product_image.png |product: http://product_url.html") puts result[1] # http://product_image.png puts result[2] # http://product_url.html