jscript.net

Jscript .net Replace a string using regex match


I am looking for a way to replace a string using reg ex match in JScript .Net.

inputString = "this is my test string audienceId=123456 done here"

the value of the audienceId can be any 6 digit integer and is a random value.

I am using fiddler script which is based on JScript .Net.

So, I am looking for a way to replace the audienceId value in the inputString.

So far, i have tried the following and this will work only if the audienceId is a constant and does not change. Please help.

inputString = inputString.Replace('audienceId=123456', 'audienceId=')

Solution

  • inputString = inputString.replace(/audienceId=\d*/, 'audienceId=');
    

    the \d matches a digit, the * repeats the digit x times (as many as it can find in a row)