确定。举个例子:
http://example.com/news/3226-some-post-title.html
我正试图获得3226.这个正则表达式:http://interaktywnie.com/newsy/(.*)。 似乎不起作用。请帮忙。
感谢。
答案 0 :(得分:2)
答案 1 :(得分:1)
你想要这个:
/http:\/\/example.com\/news\/(\d+)-.+\.html/
\ d是任何数字。此外,以下站点对ruby中的正则表达式非常有用:
答案 2 :(得分:1)
"http://example.com/news/3226-some-post-title.html".split("/").last.to_i
答案 3 :(得分:0)
尝试这种模式:
/http:\/\/example\.com\/news\/(\d+)-.+\.html/
所以:
match = /http:\/\/example\.com\/news\/(\d+)-.+\.html/.match("http://example.com/news/3226-some-post-title.html")
puts match[1]