Regix(Regular Expression)

HTML CODING:

<!DOCTYPE html>
<html>

  <head>

     <script type="text/javascript" src="regularexpression.js">

     </script>

  </head>
   
     <body>
       <form name="myform">

        <p id="mypar">hi i'm dynamic change my text before click</p>
      
          <input type="text" name="longtext" placeholder="long text"/><br>

          <input type="button" value="slmatch" name="get" onclick="reqexp()"/>
          <input type="button" value="changetext" name="get" onclick="changetxt()"/><br>

          <input type="button" value="mlmatch" name="get" onclick="reqex()"/>
          <input type="button" value="charmatch" name="btngetchar" onclick="charmatch()"/><br>

          <input type="button" value="nomatch" name="btngetno" onclick="Nomatch()"/>
          <input type="button" value="test" name="btntest" onclick="test()"/>
          <input type="button" value="search" name="btnsearch" onclick="searchfn()"/>
       </form>
     </body>

</html>

JAVASCRIPT CODING:

 function reqexp()//single line match function
{
         var temp = document.myform.longtext.value;
         var re = new RegExp( "kathir", "g" );    
         var result = re.exec(temp);
        
         if(result == "kathir")
         {
         document.write("Kathiravan short name : " +  result);
         }
         else
         {
         document.write("does't match kathir ");
         }
}

function changetxt()//regx to change the text function
{


        var str = document.getElementById("mypar").innerHTML;
       var txt = str.replace(/before/i,"after");
       document.getElementById("mypar").innerHTML = txt; 

}

function reqex()//multi line regx checks function
{
         var temp = document.myform.longtext.value;
         var re = new RegExp( "kathir_mangalapuram", "m" );    
         var result = re.exec(temp);
        
         if(result == "kathir_mangalapuram")
         {
         document.write("Kathiravan short name : " +  result);
         }
         else
         {
         document.write("does't match kathir ");
         }
}

function charmatch()//character match function
{
     var temp = document.myform.longtext.value;
   
     if(temp.match(/[a-zA-z]+/))
     {
      document.write("its match the pardren:");
     }
     else
     {
     document.write("its doesnot match");
     }

}



function Nomatch()//it's a number match function
{
     var temp = document.myform.longtext.value;
   
     if(temp.match(/[0-9]+/))
     {
      document.write("its match the pardren:");
     }
     else
     {
     document.write("its doesnot match");
     }

}

function test()//its test keyword use the function
{
       var temp = document.myform.longtext.value;
       var str = /[a-zA-Z]+/;   
       var res = str.test(temp);

     if(temp.match(/[a-zA-z]+/))
     {
      document.write("its match the pardren:"+ res);
     }
     else
     {
     document.write("its doesnot match");
     }
 
}


function searchfn()
{
  

    var myRegExp = /Alex/;
    var string1 = "Today John went to the store and talked with Alex.";
    var matchPos1 = string1.search(myRegExp);

    if(matchPos1 != -1)
    document.write("There was a match at position " + matchPos1);
    else
    document.write("There was no match in the first string");


}





SCREEN SHOTS:




Comments

Popular posts from this blog

my reframce

Angular UI Grid To Bind JSON Data