[英]How to use href.replace in extjs
how to use href.replace in extjs 如何在extjs中使用href.replace
This is my sample: 这是我的样本:
'iconCls': 'icon_' + href.replace(/[^.]+\./, '')
href= http://localhost:1649/SFM/Default.aspx#/SFM/config/release_history.png
Now i want to get text "release_history.png"
, How i get it. 现在我想获得文本"release_history.png"
,我是如何得到它的。
Thanks 谢谢
If you just want the filename, it's probably easier to do: 如果您只想要文件名,那么可能更容易:
var href = "http://localhost:1649/SFM/Default.aspx#/SFM/config/release_history.png";
var iconCls = 'icon_' + href.split('/').pop();
Update 更新
To get the filename without the extension, you can do something similar: 要获取没有扩展名的文件名,您可以执行类似的操作:
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('.')
some regex solutions (regex including /
delimiter) 一些正则表达式解决方案(正则表达式包括/
分隔符)
as in your example code match the start of the url that can be dropped 在您的示例代码中匹配可以删除的url的开头
href.replace(/^.*\//, '')
or use a regex to get the last part of the url that you want to keep 或者使用正则表达式来获取要保留的URL的最后一部分
/(?<=\/)[^.\/]+\.[^.]+$/
update 更新
or get the icon name without .png
(this is using lookbehind and lookahead feature of regex) 或获取没有.png
的图标名称(这是使用正则表达式的lookbehind和lookahead功能)
(?<=\/)[^.\/]+(?=\.png)
Not all flavors of regex support all lookaround reatures and I think Javascript only supports lookahead. 并非所有正则表达式都支持所有外观修改,我认为Javascript只支持前瞻。 so probably your solution is this: 所以你的解决方案可能就是:
[^.\/]+(?=\.png)
code examples here: 这里的代码示例:
http://www.myregextester.com/?r=6acb5d23 http://www.myregextester.com/?r=6acb5d23
http://www.myregextester.com/?r=b0a88a0a http://www.myregextester.com/?r=b0a88a0a
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.