Exchange occurrences of character - Javascript RegExp

Javascript examples for RegExp:RegExp test

Description

Exchange occurrences of character

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.js"></script> 
      <script type="text/javascript">
    $(window).load(function(){/*from  ww  w.  j a va 2s .co  m*/
var str = 'This is test\'s "suit" this is a test';
str = str.replace(/('|")/g, function(x) {
    return x=='"' ? "'" : '"';
});
console.log(str)
    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials