Javascript Data Type How to - Retrieve the string wrapped by double quote ""








Question

We would like to know how to retrieve the string wrapped by double quote "".

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
window.onload=function(){<!--  ww w  .  j a v a2  s.c  o m-->
    var s ='hi "Hello" world';
    var r = /("(\\"|[^"])+")/g;
    var a = s.match(r);
    document.writeln(a);
}
</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: