Find a specific word between two sentences - Javascript String Operation

Javascript examples for String Operation:String Search

Description

Find a specific word between two sentences

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  ww  . ja  v  a2 s . co  m*/
let str = `My Name is
Joe
My Age is
25
My phone is
Nokia`
let matches = str.match(/My Age Is\s?\n([0-9]+)/i)
let age = matches[1];
console.log('Age is ' + age)
    }

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

Related Tutorials