href.replace如何使用ExtJS的如何使用ExtJS的
href.replace这是我的示例:
'iconCls': 'icon_' + href.replace(/[^.]+\./, '')
href= http://localhost:1649/SFM/Default.aspx#/SFM/config/release_history.png
现在我想文字"release_history.png"
,我怎么得到它。
感谢
href.replace如何使用ExtJS的如何使用ExtJS的
href.replace这是我的示例:
'iconCls': 'icon_' + href.replace(/[^.]+\./, '')
href= http://localhost:1649/SFM/Default.aspx#/SFM/config/release_history.png
现在我想文字"release_history.png"
,我怎么得到它。
感谢
如果你只是想在文件名,它可能更容易做:
var href = "http://localhost:1649/SFM/Default.aspx#/SFM/config/release_history.png";
var iconCls = 'icon_' + href.split('/').pop();
更新
要得到的文件名不带扩展名,你可以做同样的事情:
var filename = "release_history.png";
var without_ext = filename.split('.');
// Get rid of the extension
without_ext.pop()
// Join the filename back together, in case
// there were any other periods in the filename
// and to get a string
without_ext = without_ext.join('.')
一些正则表达式s olutions(正则表达式包括/
分隔符)
在您的示例代码匹配,可以添加
href.replace(/^.*\//, '')
或使用正则表达式来获得要保持URL的最后部分的URL的开始
/(?<=\/)[^.\/]+\.[^.]+$/
更新
或获取图标名称不.png
(这是使用正则表达式的回顾后和预读功能)
(?<=\/)[^.\/]+(?=\.png)
不是正则表达式支持所有环视reatures所有的口味和我想的Javascript只支持先行。所以可能是你的解决方案是这样的:
[^.\/]+(?=\.png)
代码示例在这里:
http://www.myregextester.com/?r=6acb5d23
http://www.myregextester.com/?r=b0a88a0a
感谢您的回答,还有一个问题我如何获得文本”release_history.png“而不是”.png“ – xoops 2011-04-08 09:32:34
您可以尝试'/(?<= \ /)[^。\ /] +(?= \ .PNG)/' – 2011-04-08 09:42:10
谢谢您的回答,一个问题我如何获得文本 “release_history.png” 无”。 png“ – xoops 2011-04-08 09:21:43