Google Ads

PHP RegEx: With Meta Characters PHP Script


PHP RegEx: With Meta Characters PHP Script

In our last tutorials regarding ReGex we have some simple pattern of matching. We also use caret (^) For matching at the beginning of the string and (\z) to match at the end of the string. These characters are called Meta Characters and shown below.

a. . (Full stop)
b. ^ (Carat)
c. * (Asterix)
d. + (Plus)
e. ? (Question Mark)
f. { (Opening curly brace)
g. [ (Opening brace)
h. ] (Closing brace)
i. \ (Backslash)
g. | (Pipe)
k. ( (Opening parens)
l. ) (Closing parens)
m. } (Closing curly brace)

Above characters are very useful in terms of ReGex. But if you search a character that include with special character of Meta Characters. Then we need to escape it using backslash.

Sample string: 1+2=3

 

 
 
  1. <?php
  2. // create a string
  3. $string = '1+2=3';
  4. // try to match our pattern
  5. if(preg_match("/^1\+2/i", $string)) {
  6. // if the pattern matches we echo this
  7. echo 'The string begins with 1+2';
  8. } else {
  9. // if no match is found we echo this line
  10. echo 'No match found';
  11. }
  12. ?>

 

From the code above you will see the script that display:
“The string begins with 1+2” because if found the pattern 1+2 and escape the special meaning of + symbol in Meta characters.
I you would not escape the the character preg_match("/^1+1/i/", $string); then it will display “No match found”.

 

 


Related Post

Rx Tera v2.0 – Complete Pharmacy Management ... Rx Tera v2.0 - Complete Pharmacy Management ApplicationRx Tera v2.0 - Complete Pharmacy Management ApplicationRx Tera 2.0 is a web based Pharmacy Mana...
CrazyParking-Html5 Game PHP Script Download CrazyParking-Html5 GameCrazyParking-Html5 GameCrazy Parking is a simple 2D physics puz game(included c2 source files)Demo: http://codecanyon.net/item/...
ChatOne v1.6 – Social Networking PHP Script ChatOne is a PHP Social Network Script, ChatOne is the best way to start your own social network website ! ChatOne is fast, secured, and it will be re...
PHPfox v3.4.0 Beta 2 PHP Script Download PHPfox v3.4.0 Beta 2 PHP Script Download Create a beautiful Social Network like Facebook, Twitter, Myspace etc. This is a popular PHP Script in ...
AtoZ SEO Tools v2.0 – Search Engine Optimiza... AtoZ SEO Tools v2.0 - Search Engine Optimization Tools PHP Script A to Z SEO Tools is a Search Engine Optimization Tools. We have more than 50 SEO ...

Have any Question or Comment?

Leave a Reply

Your email address will not be published. Required fields are marked *

"