0

I have string like this

<html>
    [[Wayfinder? &amp;startId=`0` &amp;outerClass=`art-hmenu` ]] &amp;
    &amp; 
</html>

I want to change all &amp; that inside of [[ and ]] will be replaced by &

How to do that with javascript?

1 Answer 1

5
str.replace(/\[\[(.*)?]]/, function(match) {
    return match.replace(/&amp;/g, '&');
});

Here's the fiddle: http://jsfiddle.net/Jtv5a/

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

2 Comments

Better: Change /\[\[(.*)?\]\]/ to /\[\[(.{4})?\]\]/
@qwertymk - I don't really see how that's any better. All it'll do is prevent the second regex from running if the text inside is less than 4 characters long. Not really that much of a benefit.

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.