小编ben*_*aay的帖子

Removing utm_* parameters from URL in javascript with a regex

I did not find any good answer to this question so I share what I found and works

if you want to remove all the google analytics terms from an URL, you mostly want to keep the other parameters and get a clean valid URL at the end

url = url.replace(/(\&|\?)utm([_a-z0-9=+\-]+)/igm, "$1");
Run Code Online (Sandbox Code Playgroud)

with a url like this https://www.somewebsite.fr/produit/yi-camera-3600-noir-vr-33705370/offre-81085802?utm_source=325483&utm_medium=affiliation&utm_content=catalogue-RDC&awc=6901_1530705916_88ef12642ad61dfc5239ba01bbbe5249

you will get this https://www.somewebsite.fr/produit/yi-camera-3600-noir-vr-33705370/offre-81085802?&&&awc=6901_1530705916_88ef12642ad61dfc5239ba01bbbe5249

this url is already valid but we have some dupe & signs if you remove the $1 …

javascript regex url clean-urls node.js

1
推荐指数
1
解决办法
1403
查看次数

标签 统计

clean-urls ×1

javascript ×1

node.js ×1

regex ×1

url ×1