0

My URL is like :

https://www.example.com?vid=123124321524

I will have to replace vid value with "--notavailable--" So it should be:

https://www.example.com?vid=--notavailable--

I will have to use JS .replace() function(I have to use Regex).

There might be multiple params, should be exact param(XXXvid should NOT match)

Basically i have to pass solution to array like: ["regex","new param value"]

For example

  "https://www.example.com?vid=123124321524".replace(/[?|&]vid=\K([^&#]*)/,"--notavailable--")

Why is not working? EDIT: I realised it work with php not JS

I have tried lots of thing, still no luck. Thanks!

1 Answer 1

1

I guess javascript doesn't know \K, you could use:

var input = "https://www.example.com?vid=123124321524"
var output = input.replace(/([?&]vid=)[^&#]+/,"$1--notavailable--");
console.log(output);

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.