How to remove two parts of a string with JavaScript?

JavascriptWeb DevelopmentFront End Technology

To remove text between two parts of a string, use JavaScript regex.

Example

You can try to run the following code to learn how to remove text between parentheses −

 Live Demo

<html>
   <head>
      <script>
         var str = "Welcome to Qries (website)";
         document.write(str);
       
         // Removing text between parentheses
         document.write("<br>"+str.replace(/ *\([^)]*\) */g, ""));
      </script>
   </head>
   
   <body>
   </body>
</html>

Output

raja
Updated on 23-Jun-2020 05:29:46

Advertisements