1

I have the following snippet where I try to replace on variable values with javascripts Regexp. But I can not figure out how should look to work

var str = 'display = 12;14&test =124;562'; 
var str2 = 'display';
new_values = '123;185';
var new_str = str.replace(new RegExp( str2 + '/=^[0-9];[0-9]'),  new_values )
console.log(new_str);

http://jsfiddle.net/2b4xx/2/

1 Answer 1

1

Your regex is wrong as there is no / in the input text and ^ is only valid at start and inside character class.

Try this:

var new_str = str.replace(new RegExp( str2 + ' *= *[0-9]+;[0-9]+' ), new_values );
console.log(new_str);
Sign up to request clarification or add additional context in comments.

1 Comment

yes thank you very much I had a lot of problems on equal sign

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.