Reputation: 1862
Hey guys i need to replace a string which starts every time with the same parts. Such as…
var name = $('.item').attr('name'); // Could be »item-name-XYZ« (XYZ) differs each time.
name.replace('item-name-?', 'item-name-newone');
items can appear many times and i do have to replace all names of them. I guess its something with regex…
Thanks in advance.
BTW: My most asked questions are about regex. Does someone has a good source to learn it?
Upvotes: 0
Views: 132
Reputation: 221
You don't need regex for this, you can use javascript
var newone = name.substr(0,10) + 'Xyy';
Upvotes: 0
Reputation: 12042
Yes, it is about regex. You can learn them here
Your code will look like this:
name.replace(/item-name-(.*)/, 'item-name-newone');
Upvotes: 1