xoops
xoops

Reputation: 701

How to use href.replace in extjs

how to use href.replace in extjs

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.

Thanks

Upvotes: 0

Views: 352

Answers (2)

bw_üezi
bw_üezi

Reputation: 4564

some regex solutions (regex including / delimiter)

as in your example code match the start of the url that can be dropped

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

or use a regex to get the last part of the url that you want to keep

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

update

or get the icon name without .png (this is using lookbehind and lookahead feature of regex)

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

Not all flavors of regex support all lookaround reatures and I think Javascript only supports lookahead. so probably your solution is this:

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


code examples here:
http://www.myregextester.com/?r=6acb5d23
http://www.myregextester.com/?r=b0a88a0a

Upvotes: 0

Gary Chambers
Gary Chambers

Reputation: 25838

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

Upvotes: 2

Related Questions