Reputation:
Whats the easiest way in javascript to replace ABC, DEF, GHI with XYZ in the following strings
http://z.site.com/z/ABC/z/z.html
http://z.site.com/z/DEF/z/z.html
http://z.site.com/z/GHI/z/z.html
Upvotes: 1
Views: 438
Reputation: 45116
You can use a regular expression to detect that pattern and change the three letters in question:
s = s.replace(/^http:\/\/z\.site\.com\/z\/.../, 'http://z.site.com/z/XYZ');
Upvotes: 1
Reputation: 4132
var url = "http://z.site.com/z/ABC/z/z.html";
url = url.replace(/ABC|DEF|GHI/, "XYZ");
Upvotes: 4