sauLVP

RegExp

Jan 31st, 2018
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Regular Expression</title>
  5. </head>
  6. <body>
  7. <script>
  8.     var s="This is a demonstration of the \"JavaScript\" Regular Expression Object0";
  9.     with(document)
  10.     {
  11.         write("s="+s);
  12.         write("<hr><b>Bracket Expressions</b>");
  13.         write("<br>match(/[d-n]/)="+s.match(/[d-n]/));
  14.         write("<br>match(/[d-n]/g)="+s.match(/[d-n]/g));
  15.         write("<br>match(/[^d-n]/)="+s.match(/[^d-n]/));
  16.         write("<br>match(/[^d-n]/g)="+s.match(/[^d-n]/g));
  17.         write("<br>match(/[aRE]/g)="+s.match(/[aRE]/g));
  18.         write("<br>match(/[A-Z]/g)="+s.match(/[A-Z]/g));       
  19.         write("<br>match(/[0-9]/g)="+s.match(/[0-9]/g));
  20.         write("<br>match(/is|of|on/g)="+s.match(/is|of|on/g));
  21.         write("<hr><b>Metacharacters</b>");
  22.         write("<br>match(/.e/g)="+s.match(/.e/g));
  23.         write("<br>match(/.r./g)="+s.match(/.r./g));
  24.         write("<br>match(/\w/g)="+s.match(/\w/g));
  25.         write("<br>match(/\W/g)="+s.match(/\W/g));
  26.         write("<br>match(/\d/g)="+s.match(/\d/g));
  27.         write("<br>match(/\D/g)="+s.match(/\D/g));
  28.         write("<br>match(/\s/g)="+s.match(/\s/g));
  29.         write("<br>match(/\S/g)="+s.match(/\S/g));
  30.         write("<br>match(/\ bt/gi)="+s.match(/\bt/gi));
  31.         write("<br>match(/\Bt/g)="+s.match(/\Bt/g));
  32.         write("<hr><b>Quantifiers</b>");
  33.         write("<br>match(/s+/g)="+s.match(/s+/g));
  34.         write("<br>match(/\w+/g)="+s.match(/\w+/g));
  35.         write("<br>match(/\W+/g)="+s.match(/\W+/g));
  36.         s1="Helloooo World!!! Hello World!!!";
  37.         write("<p>s1="+s1);
  38.         write("<br>match(/lo*/g)="+s1.match(/lo*/g));
  39.         write("<br>match(/lo?/g)="+s1.match(/lo?/g));
  40.         write("<p>");
  41.         write("<br>match(/s{2}/g)="+s.match(/s{2}/g));
  42.         write("<br>match(/\w{6,13}/g)="+s.match(/\w{6,13}/g));
  43.         s2="10,100,1000,10000,100000";
  44.         write("<p>");
  45.         write("<br>match(/\d{4,}/g)="+s2.match(/\d{4,}/g));
  46.         write("<p>");
  47.         write("<br>match(/\w$/g)="+s.match(/\w$/g));
  48.         write("<br>match(/^t/gi)="+s.match(/^t/gi));
  49.         write("<p>");  
  50.         write("<br>match(/on(?=\w}/g)="+s.match(/on(?=\w)/g));
  51.         write("<br>match(/on(?!\w}/g)="+s.match(/on(?!\w)/g));
  52.         write("<hr><b>Modifiers</b>");
  53.         p=/on(?=\w)/g;
  54.         if(p.global)
  55.             write("<br>g modifier is set");
  56.         else
  57.             write("<br>g modifier is reset");  
  58.         if(p.ignoreCase)
  59.             write("<br>i modifier is set");
  60.         else
  61.             write("<br>i modifier is reset");      
  62.         if(p.multiline)
  63.             write("<br>m modifier is set");
  64.         else
  65.             write("<br>m modifier is not set");
  66.         write("<hr><b>Methods</b>");
  67.         p1=/[0-9]/g;
  68.         var result=p1.exec(s);
  69.         write("<br>Result="+result);
  70.         if(p1.test(s)==true)
  71.             write("<br>String contains digits");
  72.         else
  73.             write("<br>String does not contain digits");
  74.         p2=/[A-Z]/g;
  75.         write("<br>Upper case characters in the string are at positions");
  76.         while(p2.test(s)==true)
  77.             write("<br>"+p2.lastIndex);
  78.     }
  79. </script>
  80. </body>
  81. </html>
Add Comment
Please, Sign In to add comment