Match besides first word and words starting with one or two hyphens - Javascript RegExp

Javascript examples for RegExp:RegExp Match

Description

Match besides first word and words starting with one or two hyphens

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 ww w.ja v a  2 s. co m*/
var str = 'test --par2 --par23 = asdf 0 aa true hello "test test"';
var re = /("[^"]+")|^\S+|\W-\S+|(\S+)/g;
var res = []
while ((m = re.exec(str)) !== null) {
  if(m[1] != undefined) res.push(m[1]);
  if(m[2] != undefined) res.push(m[2]);
}
console.log(res);
    }

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

Related Tutorials