Read characters within brackets () inside a string - Javascript String Operation

Javascript examples for String Operation:String Search

Description

Read characters within brackets () inside a string

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {//from  w  w  w  . j a  v a  2  s .  c  o  m
function myFunction() {
    var s = "Hello (World) This is (Working)";
    var i = 0;
    var outputs = [];
    while ((i = s.indexOf('(', i)) != -1) {
        var stop = s.indexOf(')', i);
        outputs.push(s.slice(i + 1, stop));
        i++;
    }
    document.write(outputs.join(' '));
}
myFunction();
    });

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

Related Tutorials