Computer >> Computer tutorials >  >> Programming >> Javascript

How to remove two parts of a string with JavaScript?


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 −

<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

How to remove two parts of a string with JavaScript?