如何匹配文本中的特定数字 - Ruby正则表达式

时间:2013-04-05 05:56:42

标签: ruby regex

    id="profile_photo_link" href="/photo83085640_283973341" onclick="return showPhoto('83085640_283973341', 'album8308564
    0_0/rev', 

{temp:{base:"http://cs301701.vk.me/v301701640/",x_:["181d/N_1czOIgH0s",556,313]},

jumpTo:
    {z: 'albums83085640'}}, event)">

<img width="200" height="205" src="http://cs301701.vk.me/v301701640/4a03/mfKV3wOhrqU.jpg
    " alt="Сергей On-line Консультации Василюк">

如何匹配ruby regex上面的这个(83085640)数字?正则表达式的开头必须在showPhoto之后('text并在此处结束_在数字之后

请帮忙!

1 个答案:

答案 0 :(得分:0)

您只需执行以下操作:

my_text = "showPhoto('83085640_283973341',";    #Input string. I'm only using a part of it here for convenience.
pat = /showPhoto\('(\d*)_/;    #The Regexp pattern as per your requirements.

puts(pat.match(my_text)[1]);

输出:

83085640