Saturday, March 23, 2019

Regular Expression Replace Function for B.C.A.,M.C.A. and All IT Students


--------------------------------------------------------------------------------------------------------------------------
Prepared By : Uday Shah (HOD - IT)
E-Mail : rupareleducation@gmail.com
Contact No : 7600044051


Regular Expression Replace Function

#Press the follow button to get update.


<?php
          $copy_date = "Copyright 1999";
          $copy_date = preg_replace("([0-9]+)", "2000", $copy_date);
          print $copy_date;
?>
Regular Expression Split Function
<?php

          $ip = "123.456.789.000"; // some IP address
          $iparr = preg_split ("/\./", $ip);
  
          print "$iparr[0] <br />";
          print "$iparr[1] <br />";
          print "$iparr[2] <br />";
          print "$iparr[3] <br />";
?>
<?php
          $my_text="I Love India";
          $my_array  = preg_split("/ /", $my_text);
          print_r($my_array );
?>
Regular Expression Match Function
<?php
          $my_url = "www.rupareleducation.com";
          if (preg_match("/education/", $my_url))
          {
                   echo "the url $my_url contains education";
          }
          else
          {
                   echo "the url $my_url does not contain education";
          }
?>
<?php
          $my_email = "rupareleducation@company.com";
          if (preg_match("/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/", $my_email))
          {
                   echo "$my_email is a valid email address";
          }
          else
          {
                   echo "$my_email is NOT a valid email address";
          }?>


Explaining the pattern "[/^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z.]{2,5}$/]"

HERE,

·        "'/.../'" starts and ends the regular expression

·        "^[a-zA-Z0-9._-]" matches any lower or upper case letters, numbers between 0 and 9 and dots, underscores or dashes.

·        "+@[a-zA-Z0-9-]" matches the @ symbol followed by lower or upper case letters, numbers between 0 and 9 or dashes.

·        "+\.[a-zA-Z.]{2,5}$/" escapes the dot using the backslash then matches any lower or upper case letters with a character length between 2 and 5 at the end of the string.


#Press the follow button to get update.

:: Best of Luck  ::

https://myshopprime.com/uday.shah3/shop

Please share and comment it. Thank you...