1<?php
2//Syntex : int preg_match( $pattern, $input, $matches, $flags, $offset)
3
4// Declare a variable and initialize it
5$str = "Check For Testing.";
6
7// case-Insensitive search for the word "Check"
8if (preg_match("/\bCheck\b/i", $str, $match))
9 echo "Matched!";
10else
11 echo "not matched";
12
13
14// Output : Matched
15?>
1<?php
2 $line = "Vi is the greatest word processor ever created!";
3 // perform a case-Insensitive search for the word "Vi"
4
5 if (preg_match("/\bVi\b/i", $line, $match)) :
6 print "Match found!";
7 endif;
8?>
1<?php
2$my_email = "name@company.com";
3if (preg_match("/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/", $my_email)) {
4echo "$my_email is a valid email address";
5}
6else
7{
8 echo "$my_email is NOT a valid email address";
9}
10?>
1<?php
2$my_url = "www.guru99.com";
3if (preg_match("/guru/", $my_url))
4{
5 echo "the url $my_url contains guru";
6}
7else
8{
9 echo "the url $my_url does not contain guru";
10}
11?>
1<?php
2
3$my_text="I Love Regular Expressions";
4
5$my_array = preg_split("/ /", $my_text);
6
7print_r($my_array );
8
9?>
1int preg_match (string pattern, string string [, array pattern_array], [, int $flags [, int $offset]]]);
2
1<html>
2
3 <head>
4 <title>Hello World</title>
5 </head>
6
7 <body>
8 <?php echo "Hello, World!";?>
9 </body>
10
11</html>