Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <title>Regular Expression</title>
- </head>
- <body>
- <script>
- var s="This is a demonstration of the \"JavaScript\" Regular Expression Object0";
- with(document)
- {
- write("s="+s);
- write("<hr><b>Bracket Expressions</b>");
- write("<br>match(/[d-n]/)="+s.match(/[d-n]/));
- write("<br>match(/[d-n]/g)="+s.match(/[d-n]/g));
- write("<br>match(/[^d-n]/)="+s.match(/[^d-n]/));
- write("<br>match(/[^d-n]/g)="+s.match(/[^d-n]/g));
- write("<br>match(/[aRE]/g)="+s.match(/[aRE]/g));
- write("<br>match(/[A-Z]/g)="+s.match(/[A-Z]/g));
- write("<br>match(/[0-9]/g)="+s.match(/[0-9]/g));
- write("<br>match(/is|of|on/g)="+s.match(/is|of|on/g));
- write("<hr><b>Metacharacters</b>");
- write("<br>match(/.e/g)="+s.match(/.e/g));
- write("<br>match(/.r./g)="+s.match(/.r./g));
- write("<br>match(/\w/g)="+s.match(/\w/g));
- write("<br>match(/\W/g)="+s.match(/\W/g));
- write("<br>match(/\d/g)="+s.match(/\d/g));
- write("<br>match(/\D/g)="+s.match(/\D/g));
- write("<br>match(/\s/g)="+s.match(/\s/g));
- write("<br>match(/\S/g)="+s.match(/\S/g));
- write("<br>match(/\ bt/gi)="+s.match(/\bt/gi));
- write("<br>match(/\Bt/g)="+s.match(/\Bt/g));
- write("<hr><b>Quantifiers</b>");
- write("<br>match(/s+/g)="+s.match(/s+/g));
- write("<br>match(/\w+/g)="+s.match(/\w+/g));
- write("<br>match(/\W+/g)="+s.match(/\W+/g));
- s1="Helloooo World!!! Hello World!!!";
- write("<p>s1="+s1);
- write("<br>match(/lo*/g)="+s1.match(/lo*/g));
- write("<br>match(/lo?/g)="+s1.match(/lo?/g));
- write("<p>");
- write("<br>match(/s{2}/g)="+s.match(/s{2}/g));
- write("<br>match(/\w{6,13}/g)="+s.match(/\w{6,13}/g));
- s2="10,100,1000,10000,100000";
- write("<p>");
- write("<br>match(/\d{4,}/g)="+s2.match(/\d{4,}/g));
- write("<p>");
- write("<br>match(/\w$/g)="+s.match(/\w$/g));
- write("<br>match(/^t/gi)="+s.match(/^t/gi));
- write("<p>");
- write("<br>match(/on(?=\w}/g)="+s.match(/on(?=\w)/g));
- write("<br>match(/on(?!\w}/g)="+s.match(/on(?!\w)/g));
- write("<hr><b>Modifiers</b>");
- p=/on(?=\w)/g;
- if(p.global)
- write("<br>g modifier is set");
- else
- write("<br>g modifier is reset");
- if(p.ignoreCase)
- write("<br>i modifier is set");
- else
- write("<br>i modifier is reset");
- if(p.multiline)
- write("<br>m modifier is set");
- else
- write("<br>m modifier is not set");
- write("<hr><b>Methods</b>");
- p1=/[0-9]/g;
- var result=p1.exec(s);
- write("<br>Result="+result);
- if(p1.test(s)==true)
- write("<br>String contains digits");
- else
- write("<br>String does not contain digits");
- p2=/[A-Z]/g;
- write("<br>Upper case characters in the string are at positions");
- while(p2.test(s)==true)
- write("<br>"+p2.lastIndex);
- }
- </script>
- </body>
- </html>
Add Comment
Please, Sign In to add comment