Parse string statement with regex match function - Javascript RegExp

Javascript examples for RegExp:RegExp Match

Description

Parse string statement with regex match function

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 .ja v a  2  s  .co m
let text = '["ABC"]["DEF"]["XUZ"]';
let results = text.match(/\["(.*)"\]\["(.*)"]/)

// results[0] is always the entire string!
console.log(results[0]);

let first = results[1];
let second = results[2];
console.log("First: "+first+"\nSecond: "+second);


    }

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

Related Tutorials