String replace Double quotes into curly brackets [duplicate]

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












6















This question already has an answer here:



  • Converting ″Straight Quotes″ to “Curly Quotes”

    7 answers



How to replace all the Double quotes into both open and close curly brackets.



let str = "This" is my "new" key "string";


I tried with this regex



str.replace(/"/,'').replace(/"/,'')


But I end up with this:



This is my "new" key "string"


Here am getting only the first word is changing but i would like to change all the words.
I want the result to be:



This is my new key string


Thanks in advance.










share|improve this question















marked as duplicate by Wiktor Stribiżew javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Dec 23 '18 at 13:01


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1




    I kind of agree with whoever voted to reopen this question. While the question about smart quotes is quite similar, someone looking for a simple way to replace symmetrical delimiters with balanced pairs would need to scroll quite far down to find the only answer that doesn't assume the input is English prose text there.
    – Ilmari Karonen
    Dec 23 '18 at 20:14
















6















This question already has an answer here:



  • Converting ″Straight Quotes″ to “Curly Quotes”

    7 answers



How to replace all the Double quotes into both open and close curly brackets.



let str = "This" is my "new" key "string";


I tried with this regex



str.replace(/"/,'').replace(/"/,'')


But I end up with this:



This is my "new" key "string"


Here am getting only the first word is changing but i would like to change all the words.
I want the result to be:



This is my new key string


Thanks in advance.










share|improve this question















marked as duplicate by Wiktor Stribiżew javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Dec 23 '18 at 13:01


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1




    I kind of agree with whoever voted to reopen this question. While the question about smart quotes is quite similar, someone looking for a simple way to replace symmetrical delimiters with balanced pairs would need to scroll quite far down to find the only answer that doesn't assume the input is English prose text there.
    – Ilmari Karonen
    Dec 23 '18 at 20:14














6












6








6








This question already has an answer here:



  • Converting ″Straight Quotes″ to “Curly Quotes”

    7 answers



How to replace all the Double quotes into both open and close curly brackets.



let str = "This" is my "new" key "string";


I tried with this regex



str.replace(/"/,'').replace(/"/,'')


But I end up with this:



This is my "new" key "string"


Here am getting only the first word is changing but i would like to change all the words.
I want the result to be:



This is my new key string


Thanks in advance.










share|improve this question
















This question already has an answer here:



  • Converting ″Straight Quotes″ to “Curly Quotes”

    7 answers



How to replace all the Double quotes into both open and close curly brackets.



let str = "This" is my "new" key "string";


I tried with this regex



str.replace(/"/,'').replace(/"/,'')


But I end up with this:



This is my "new" key "string"


Here am getting only the first word is changing but i would like to change all the words.
I want the result to be:



This is my new key string


Thanks in advance.





This question already has an answer here:



  • Converting ″Straight Quotes″ to “Curly Quotes”

    7 answers







javascript regex string replace






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 23 '18 at 7:01









Jack Bashford

5,66131235




5,66131235










asked Dec 23 '18 at 6:36









YuvaMac

619




619




marked as duplicate by Wiktor Stribiżew javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Dec 23 '18 at 13:01


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Wiktor Stribiżew javascript
Users with the  javascript badge can single-handedly close javascript questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Dec 23 '18 at 13:01


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









  • 1




    I kind of agree with whoever voted to reopen this question. While the question about smart quotes is quite similar, someone looking for a simple way to replace symmetrical delimiters with balanced pairs would need to scroll quite far down to find the only answer that doesn't assume the input is English prose text there.
    – Ilmari Karonen
    Dec 23 '18 at 20:14













  • 1




    I kind of agree with whoever voted to reopen this question. While the question about smart quotes is quite similar, someone looking for a simple way to replace symmetrical delimiters with balanced pairs would need to scroll quite far down to find the only answer that doesn't assume the input is English prose text there.
    – Ilmari Karonen
    Dec 23 '18 at 20:14








1




1




I kind of agree with whoever voted to reopen this question. While the question about smart quotes is quite similar, someone looking for a simple way to replace symmetrical delimiters with balanced pairs would need to scroll quite far down to find the only answer that doesn't assume the input is English prose text there.
– Ilmari Karonen
Dec 23 '18 at 20:14





I kind of agree with whoever voted to reopen this question. While the question about smart quotes is quite similar, someone looking for a simple way to replace symmetrical delimiters with balanced pairs would need to scroll quite far down to find the only answer that doesn't assume the input is English prose text there.
– Ilmari Karonen
Dec 23 '18 at 20:14













4 Answers
4






active

oldest

votes


















9














Try using a global regex and use capture groups:






let str = '"This" is my "new" key "string"';
str = str.replace(/"([^"]*)"/g, '$1');
console.log(str);





The "([^"]*)" regex captures a ", followed by 0 or more things that aren't another ", and a closing ". The replacement uses $1 as a reference for the things that were wrapped in quotes.






share|improve this answer






























    4














    Your code currently is only working for the first occurrence of each and . The easiest way to fix this would be to loop while there is still a " in str:






    let str = '"This" is my "new" key "string"';
    while (str.includes('"'))
    str = str.replace(/"/,'').replace(/"/,'');

    console.log(str);








    share|improve this answer




























      1














      Try like this



      str.replace(/"(.*?)"/g, "$1")


      we need to use g-gobal flag. Here capturing string between double quotes "", then replace with matched string curly braces






      share|improve this answer




























        0














        A very simple way to do that is to iterate over string as an array and every time it encounters character " replace it either by or by repeatedly.






        let str = '"This" is my "new" key "string"';
        let strArray = str.split("");
        let open = true;
        for (let i = 0; i < strArray.length; ++i)
        if (strArray[i] == '"')
        if (open === true)
        strArray[i] = '';

        else
        strArray[i] = '';

        open = (open == true) ? false : true;


        str = strArray.join("");
        console.log(str)








        share|improve this answer



























          4 Answers
          4






          active

          oldest

          votes








          4 Answers
          4






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          9














          Try using a global regex and use capture groups:






          let str = '"This" is my "new" key "string"';
          str = str.replace(/"([^"]*)"/g, '$1');
          console.log(str);





          The "([^"]*)" regex captures a ", followed by 0 or more things that aren't another ", and a closing ". The replacement uses $1 as a reference for the things that were wrapped in quotes.






          share|improve this answer



























            9














            Try using a global regex and use capture groups:






            let str = '"This" is my "new" key "string"';
            str = str.replace(/"([^"]*)"/g, '$1');
            console.log(str);





            The "([^"]*)" regex captures a ", followed by 0 or more things that aren't another ", and a closing ". The replacement uses $1 as a reference for the things that were wrapped in quotes.






            share|improve this answer

























              9












              9








              9






              Try using a global regex and use capture groups:






              let str = '"This" is my "new" key "string"';
              str = str.replace(/"([^"]*)"/g, '$1');
              console.log(str);





              The "([^"]*)" regex captures a ", followed by 0 or more things that aren't another ", and a closing ". The replacement uses $1 as a reference for the things that were wrapped in quotes.






              share|improve this answer














              Try using a global regex and use capture groups:






              let str = '"This" is my "new" key "string"';
              str = str.replace(/"([^"]*)"/g, '$1');
              console.log(str);





              The "([^"]*)" regex captures a ", followed by 0 or more things that aren't another ", and a closing ". The replacement uses $1 as a reference for the things that were wrapped in quotes.






              let str = '"This" is my "new" key "string"';
              str = str.replace(/"([^"]*)"/g, '$1');
              console.log(str);





              let str = '"This" is my "new" key "string"';
              str = str.replace(/"([^"]*)"/g, '$1');
              console.log(str);






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Dec 23 '18 at 6:49









              Nick Parsons

              4,8222721




              4,8222721










              answered Dec 23 '18 at 6:46









              puddi

              73138




              73138























                  4














                  Your code currently is only working for the first occurrence of each and . The easiest way to fix this would be to loop while there is still a " in str:






                  let str = '"This" is my "new" key "string"';
                  while (str.includes('"'))
                  str = str.replace(/"/,'').replace(/"/,'');

                  console.log(str);








                  share|improve this answer

























                    4














                    Your code currently is only working for the first occurrence of each and . The easiest way to fix this would be to loop while there is still a " in str:






                    let str = '"This" is my "new" key "string"';
                    while (str.includes('"'))
                    str = str.replace(/"/,'').replace(/"/,'');

                    console.log(str);








                    share|improve this answer























                      4












                      4








                      4






                      Your code currently is only working for the first occurrence of each and . The easiest way to fix this would be to loop while there is still a " in str:






                      let str = '"This" is my "new" key "string"';
                      while (str.includes('"'))
                      str = str.replace(/"/,'').replace(/"/,'');

                      console.log(str);








                      share|improve this answer












                      Your code currently is only working for the first occurrence of each and . The easiest way to fix this would be to loop while there is still a " in str:






                      let str = '"This" is my "new" key "string"';
                      while (str.includes('"'))
                      str = str.replace(/"/,'').replace(/"/,'');

                      console.log(str);








                      let str = '"This" is my "new" key "string"';
                      while (str.includes('"'))
                      str = str.replace(/"/,'').replace(/"/,'');

                      console.log(str);





                      let str = '"This" is my "new" key "string"';
                      while (str.includes('"'))
                      str = str.replace(/"/,'').replace(/"/,'');

                      console.log(str);






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Dec 23 '18 at 6:45









                      Jack Bashford

                      5,66131235




                      5,66131235





















                          1














                          Try like this



                          str.replace(/"(.*?)"/g, "$1")


                          we need to use g-gobal flag. Here capturing string between double quotes "", then replace with matched string curly braces






                          share|improve this answer

























                            1














                            Try like this



                            str.replace(/"(.*?)"/g, "$1")


                            we need to use g-gobal flag. Here capturing string between double quotes "", then replace with matched string curly braces






                            share|improve this answer























                              1












                              1








                              1






                              Try like this



                              str.replace(/"(.*?)"/g, "$1")


                              we need to use g-gobal flag. Here capturing string between double quotes "", then replace with matched string curly braces






                              share|improve this answer












                              Try like this



                              str.replace(/"(.*?)"/g, "$1")


                              we need to use g-gobal flag. Here capturing string between double quotes "", then replace with matched string curly braces







                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Dec 23 '18 at 6:48









                              Raja Jaganathan

                              8,68431723




                              8,68431723





















                                  0














                                  A very simple way to do that is to iterate over string as an array and every time it encounters character " replace it either by or by repeatedly.






                                  let str = '"This" is my "new" key "string"';
                                  let strArray = str.split("");
                                  let open = true;
                                  for (let i = 0; i < strArray.length; ++i)
                                  if (strArray[i] == '"')
                                  if (open === true)
                                  strArray[i] = '';

                                  else
                                  strArray[i] = '';

                                  open = (open == true) ? false : true;


                                  str = strArray.join("");
                                  console.log(str)








                                  share|improve this answer

























                                    0














                                    A very simple way to do that is to iterate over string as an array and every time it encounters character " replace it either by or by repeatedly.






                                    let str = '"This" is my "new" key "string"';
                                    let strArray = str.split("");
                                    let open = true;
                                    for (let i = 0; i < strArray.length; ++i)
                                    if (strArray[i] == '"')
                                    if (open === true)
                                    strArray[i] = '';

                                    else
                                    strArray[i] = '';

                                    open = (open == true) ? false : true;


                                    str = strArray.join("");
                                    console.log(str)








                                    share|improve this answer























                                      0












                                      0








                                      0






                                      A very simple way to do that is to iterate over string as an array and every time it encounters character " replace it either by or by repeatedly.






                                      let str = '"This" is my "new" key "string"';
                                      let strArray = str.split("");
                                      let open = true;
                                      for (let i = 0; i < strArray.length; ++i)
                                      if (strArray[i] == '"')
                                      if (open === true)
                                      strArray[i] = '';

                                      else
                                      strArray[i] = '';

                                      open = (open == true) ? false : true;


                                      str = strArray.join("");
                                      console.log(str)








                                      share|improve this answer












                                      A very simple way to do that is to iterate over string as an array and every time it encounters character " replace it either by or by repeatedly.






                                      let str = '"This" is my "new" key "string"';
                                      let strArray = str.split("");
                                      let open = true;
                                      for (let i = 0; i < strArray.length; ++i)
                                      if (strArray[i] == '"')
                                      if (open === true)
                                      strArray[i] = '';

                                      else
                                      strArray[i] = '';

                                      open = (open == true) ? false : true;


                                      str = strArray.join("");
                                      console.log(str)








                                      let str = '"This" is my "new" key "string"';
                                      let strArray = str.split("");
                                      let open = true;
                                      for (let i = 0; i < strArray.length; ++i)
                                      if (strArray[i] == '"')
                                      if (open === true)
                                      strArray[i] = '';

                                      else
                                      strArray[i] = '';

                                      open = (open == true) ? false : true;


                                      str = strArray.join("");
                                      console.log(str)





                                      let str = '"This" is my "new" key "string"';
                                      let strArray = str.split("");
                                      let open = true;
                                      for (let i = 0; i < strArray.length; ++i)
                                      if (strArray[i] == '"')
                                      if (open === true)
                                      strArray[i] = '';

                                      else
                                      strArray[i] = '';

                                      open = (open == true) ? false : true;


                                      str = strArray.join("");
                                      console.log(str)






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Dec 23 '18 at 7:00









                                      Bishal Gautam

                                      800517




                                      800517












                                          Popular posts from this blog

                                          How to check contact read email or not when send email to Individual?

                                          Bahrain

                                          Postfix configuration issue with fips on centos 7; mailgun relay