2011-04-08 26 views
0

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",我怎麼得到它。

感謝

回答

2

如果你只是想在文件名,它可能更容易做:

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('.') 
+0

謝謝您的回答,一個問題我如何獲得文本 「release_history.png」 無」。 png「 – xoops 2011-04-08 09:21:43

0

一些正則表達式s olutions(正則表達式包括/分隔符)

在您的示例代碼匹配,可以添加

href.replace(/^.*\//, '') 

或使用正則表達式來獲得要保持URL的最後部分的URL的開始

/(?<=\/)[^.\/]+\.[^.]+$/ 

更新

或獲取圖標名稱不.png(這是使用正則表達式的回顧後和預讀功能)

(?<=\/)[^.\/]+(?=\.png) 

不是正則表達式支持所有環視reatures所有的口味和我想的Javascript只支持先行。所以可能是你的解決方案是這樣的:

[^.\/]+(?=\.png) 


代碼示例在這裏:
http://www.myregextester.com/?r=6acb5d23
http://www.myregextester.com/?r=b0a88a0a

+0

感謝您的回答,還有一個問題我如何獲得文本」release_history.png「而不是」.png「 – xoops 2011-04-08 09:32:34

+0

您可以嘗試'/(?<= \ /)[^。\ /] +(?= \ .PNG)/' – 2011-04-08 09:42:10