Escape apostrophes inside double quoted strings (Javascript)

Posted by George Sheppard on Stack Overflow See other posts from Stack Overflow or by George Sheppard
Published on 2010-04-16T13:30:17Z Indexed on 2010/04/16 13:33 UTC
Read the original article Hit count: 307

Say i have a string that i need to evaluate in javascript such as :

window.some_class.update( 'Runner', 'update_runner', '{"runner":{"id":"1","name":"Nin's Lad" } }');

In order for eval() to evaluate it, i need to escape the apostrophe in runner_name (Nin's Lad). Is this possable with regex? I dont want to escape the single quotes around Runner and update_runner. I'd just like to escape any single quotes inside double quotes.

Thanks,

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about regex