2014-11-05 51 views
0

t = "Text with numbers such as 58, 22nd, 53m2, number9 and foo44bar"更換的話,包括串號

我想提出<span>的周圍的數字是這樣的:

t.gsub(/(\d+)([[:alnum:]]+)/,"<span>\\1\\2</span>") => 
"Text with numbers such as <span>58</span>, <span>22nd</span>, <span>53m2</span>, number9 and foo<span>44bar</span>" 

我仍然有唯一的問題是這個詞的時候不啓動像number9 and "foo<span>44bar</span>一些,我也試過

t.gsub(/([[:alnum:]]+)(\d+)([[:alnum:]]+)/,"<span>\\1\\2\\3</span>")

但這也非q正確的。

我相信,我只是沒有看到一些細節,一些幫助,將不勝感激:)

回答

1

試試這個:

t.gsub(/([[:alnum:]]*(\d+)[[:alnum:]]*)/, "<span>\\1</span>") 
+0

酷,感謝:D沒錯! – MMachinegun 2014-11-05 11:42:16

相關問題