javascript - Replacing nested quotes in a faulty string inside XML Attribute using Regular Expression -
i have faulty string inside xml file: summary="the name "rambo"."
i replace inner quotes "
using regex output like:
summary="the name "
rambo"
."
this should work you, buddie!
var outer = '"the name "rambo"."'; var inner = outer.replace(/^"|"$/g, ''); var final = '"' + inner.replace(/"/g, '"') + '"'; // (string) => "the name "rambo"."
edit: shortcut little bit, it's asymmetrical because javascript not support regexp lookbehind
var str = '"the name "rambo"."'; var final = '"' + str.substr(1).replace(/"(?!$)/g, '"'); // (string) => "the name "rambo"."
edit 2: using str.slice
looks can simpler!
var str = '"the name "rambo"."'; var final = '"' + str.slice(1, -1).replace(/"/g, '"') + '"'; // (string) => "the name "rambo"."
Comments
Post a Comment