Reputation: 2517
I want to replace some diacritic characters inside URL parameter values using regular expression for finding character values.
For single character/word I make replacement with line:
url = url.replace(/null/g, "");
I can use this regular expression to find parameter values:
/\=[a-zA-Z0-9šŠđĐčČćĆžŽ]*\&/g
How to make replacement in single line (if possible)?
For example
INPUT: http://localhost:8080/page?param1=svašta¶m2=nešto¶m3=trebam
OUTPUT: http://localhost:8080/page?param1=svata¶m2=neto¶m3=trebam
Upvotes: 0
Views: 775
Reputation: 665130
You can do
url = url.replace(/\=[a-zA-Z0-9šŠđĐčČćĆžŽ]*\&/g, function(match) {
return match.replace(/[šŠđĐčČćĆžŽ]/g, "");
});
Upvotes: 1
Reputation: 89604
You don't need a regex for that, you can use encodeURI
url = url.replace(/null/g, "");
url = encodeURI(url);
Upvotes: 0