Reputation: 91
I have string like var a=""abcd""efgh""
.How do I print the output as abcd""efgh
by removing first and last double quote of a string I used a.replace(/["]/g,'')
but it is removing all the double quotes of a string.How do i get the output as abcd""efgh
.Suggest me an idea.
Upvotes: 0
Views: 61
Reputation: 9368
You can use
var a='"abcd""efgh"';
a.replace(/^"+|"+$/g, '');
From the comments here is the explanation
Explanation
^"+
and "+$
separated by |
which is the regex equivalent of the or^
is for starts-with and "+
is for one or more "
$
is for ends-with//g
is for global replacement otherwise the only the first occurrence will be replacedUpvotes: 10
Reputation: 5655
Try use this
var a='"abcd""efgh"';
a.replace(/^"|"$/g, '');
Upvotes: 0