I want to remove some parameters of my url www.domain.com?a=1&b=2&c=3
For example I have this code already from stackoverflow here which works fine:
return location.href=location.href.replace(/&?a=([^&]$|[^&]*)/i, "");
As I am not familiar with regex, how is it possible to add another parameter to this line? Right now it only removes the "a" parameter. I also want the "b" parameter to be removed too.
Edit: Ofcorse I am not using "a" and "b" as a parameter. How does it work with parameters like "crop-image" and "subscription" so the domain looks like: www.domain.com?crop-image=1&subscription=1&keep=me
Replace [ab]
with a set of capture groups of the parameters you want to remove.
location.href=location.href.replace(/&?((crop-image)|(subscription))=([^&]$|[^&]*)/gi, "");
Whatever is contained inside each group will match exactly against a full parameter name. You can or
(|
) together as many groups as you need.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다