In PHP
<ul><li>Regular Expressions are used to do pattern matching </li></ul><ul><li>PHP ,supports two types of pattern matching ...
<ul><li>Caret(^)at the beginning of regular expression: Indicates string begin searched must start with this pattern. </li...
Contd.. <ul><li>Dollar($)at end of regular expression : Indicates that string being searched must end with this pattern. <...
Contd.. <ul><li>Questionmark(?) :Indicates that preceding character should appear ZERO or ONE  times in pattern/searched s...
Contd.. <ul><li>Plus(+):Indicates that preceding character should appear ONE or MORE times in pattern. </li></ul><ul><li>E...
Contd.. <ul><li>Asterisk(*):Indicates that preceding character should appear ZERO or MORE times in pattern. </li></ul><ul>...
Contd.. <ul><li>{n}:Indicates that preceding character should appear exactly “n” times in pattern. </li></ul><ul><li>Ex. <...
Contd.. <ul><li>{n1,n2}:Indicates that preceding character should appear in pattern atleast “n1” times and atmax “n2” time...
Contd.. <ul><li>{n,}:Indicates that preceding character should appear in pattern atleast “n” times but no maximum limit . ...
Contd.. <ul><li>Dot(.):Indicates any character except newline. </li></ul><ul><li>Ex.  </li></ul><ul><li>wo.d will search “...
Contd.. <ul><li>Backslash-d(d) : Indicates any digit [0-9] </li></ul><ul><li>Ex. </li></ul><ul><li>“ wodd” will search “wo...
Contd.. <ul><li>Backslash-D(D): Indicates any character except digit [^0-9] </li></ul><ul><li>Ex. </li></ul><ul><li>woDd w...
Contd.. <ul><li>Backslash-w(w):Indicates any character, digit and underscore(_) </li></ul><ul><li>Ex. </li></ul><ul><li>“ ...
Contd.. <ul><li>Backslash-W(w): Indicates any character except letter, digit and underscore(_) </li></ul><ul><li>Ex. </li>...
Contd.. <ul><li>Backslash-s(s):Indicates any white space i.e. newline , tab , space </li></ul><ul><li>Ex. </li></ul><ul><l...
Contd.. <ul><li>Backslash-S(S):Indicates any character except white spaces i.e. space , tab , newline </li></ul><ul><li>Ex...
Contd.. <ul><li>Grouping[]:Indicates group of options </li></ul><ul><li>Ex.  </li></ul><ul><li>wo[aeiou]d will search “woa...
Contd.. <ul><li>Negotiation(^):Indicates not this group of options. </li></ul><ul><li>Ex. </li></ul><ul><li>“ wo[^aeiou]d”...
Contd.. <ul><li>Pipe(|):Indicates options for pattern. </li></ul><ul><li>Ex. </li></ul><ul><li>woo$ | ^cut will search “cu...
Contd.. <ul><li>Backslash(): to escape character. </li></ul><ul><li>Ex. </li></ul><ul><li>wo.d will search “wo.d” </li></u...
Contd.. <ul><li>Parenthesis(()):Indicates sub pattern </li></ul><ul><li>Ex. </li></ul><ul><li>w(oo)?d will search “wood” ,...
PHP  PCRE FUNCTIONS <ul><li>preg_match() : Perform a regular expression match. </li></ul><ul><li>preg_match_all() : Perfor...
REFERENCE <ul><li>http://in.php.net/manual/ </li></ul>
Upcoming SlideShare
Loading in...5
×

Regular Expressions

1,378

Published on

Basic regex tutorial

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,378
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

Regular Expressions

  1. 1. In PHP
  2. 2. <ul><li>Regular Expressions are used to do pattern matching </li></ul><ul><li>PHP ,supports two types of pattern matching POSIX and PERL type. </li></ul>
  3. 3. <ul><li>Caret(^)at the beginning of regular expression: Indicates string begin searched must start with this pattern. </li></ul><ul><li>Ex. </li></ul><ul><li>^woo will search “woo”,”wood”, “woooo” </li></ul><ul><li>but not “wow” </li></ul>
  4. 4. Contd.. <ul><li>Dollar($)at end of regular expression : Indicates that string being searched must end with this pattern. </li></ul><ul><li>Ex. </li></ul><ul><li>bie$ will search “barbie”,”newbie” </li></ul><ul><li>but not “biebar” </li></ul>
  5. 5. Contd.. <ul><li>Questionmark(?) :Indicates that preceding character should appear ZERO or ONE times in pattern/searched string </li></ul><ul><li>Ex: </li></ul><ul><li>wo? will search “wd”,”wod” but not “wood” </li></ul>
  6. 6. Contd.. <ul><li>Plus(+):Indicates that preceding character should appear ONE or MORE times in pattern. </li></ul><ul><li>Ex. </li></ul><ul><li>wo+ will search “wo”,”woo”,”wow” but not “wa” </li></ul>
  7. 7. Contd.. <ul><li>Asterisk(*):Indicates that preceding character should appear ZERO or MORE times in pattern. </li></ul><ul><li>Ex. </li></ul><ul><li>wo* will search “w”,”wo”,”wood”,”wd” </li></ul>
  8. 8. Contd.. <ul><li>{n}:Indicates that preceding character should appear exactly “n” times in pattern. </li></ul><ul><li>Ex. </li></ul><ul><li>wo{3} will search “wooo” but not “woooo” </li></ul>
  9. 9. Contd.. <ul><li>{n1,n2}:Indicates that preceding character should appear in pattern atleast “n1” times and atmax “n2” times. </li></ul><ul><li>Ex. </li></ul><ul><li>wo{2,4}d will search “wood”,”woood”,”woood” but not “wod” </li></ul>
  10. 10. Contd.. <ul><li>{n,}:Indicates that preceding character should appear in pattern atleast “n” times but no maximum limit . </li></ul><ul><li>Ex. </li></ul><ul><li>wo{2,}d will search “wood”,”woood” </li></ul><ul><li>but not “wod” </li></ul>
  11. 11. Contd.. <ul><li>Dot(.):Indicates any character except newline. </li></ul><ul><li>Ex. </li></ul><ul><li>wo.d will search “woad”,”wo9d”,”wo d” </li></ul><ul><li>but not “wo d” </li></ul>
  12. 12. Contd.. <ul><li>Backslash-d(d) : Indicates any digit [0-9] </li></ul><ul><li>Ex. </li></ul><ul><li>“ wodd” will search “wo3d”,”wo7d” </li></ul><ul><li>but not “woad” </li></ul>
  13. 13. Contd.. <ul><li>Backslash-D(D): Indicates any character except digit [^0-9] </li></ul><ul><li>Ex. </li></ul><ul><li>woDd will search “woad”,”wo@d” </li></ul><ul><li>but not “wo2d” </li></ul>
  14. 14. Contd.. <ul><li>Backslash-w(w):Indicates any character, digit and underscore(_) </li></ul><ul><li>Ex. </li></ul><ul><li>“ wowd” will search “wo0d”,”wo_d”,”woud” but not “wo&d” </li></ul>
  15. 15. Contd.. <ul><li>Backslash-W(w): Indicates any character except letter, digit and underscore(_) </li></ul><ul><li>Ex. </li></ul><ul><li>woWd will search “wo%d”,”wo@d” but not “wood” or “wo8d” </li></ul>
  16. 16. Contd.. <ul><li>Backslash-s(s):Indicates any white space i.e. newline , tab , space </li></ul><ul><li>Ex. </li></ul><ul><li>“ wosd” will search “wo d”, “wo d” but not “wood” </li></ul>
  17. 17. Contd.. <ul><li>Backslash-S(S):Indicates any character except white spaces i.e. space , tab , newline </li></ul><ul><li>Ex. </li></ul><ul><li>“ woSd” will search “wo@d”, “wood” but not “wo d” </li></ul>
  18. 18. Contd.. <ul><li>Grouping[]:Indicates group of options </li></ul><ul><li>Ex. </li></ul><ul><li>wo[aeiou]d will search “woad”, “woed” ,“woud” but not “wobd” </li></ul><ul><li>wo[aeiou]{2}d will search “woaed”, “wooud”, “woiud” but not “woaeioud” </li></ul>
  19. 19. Contd.. <ul><li>Negotiation(^):Indicates not this group of options. </li></ul><ul><li>Ex. </li></ul><ul><li>“ wo[^aeiou]d” will search “wobd”, “wo8d” but not “woad” </li></ul>
  20. 20. Contd.. <ul><li>Pipe(|):Indicates options for pattern. </li></ul><ul><li>Ex. </li></ul><ul><li>woo$ | ^cut will search “cutabcfoo” , “cutwoo” ,“abcwoo”, “cutabc” but not “woocut” </li></ul>
  21. 21. Contd.. <ul><li>Backslash(): to escape character. </li></ul><ul><li>Ex. </li></ul><ul><li>wo.d will search “wo.d” </li></ul><ul><li>wo will search “woh” </li></ul>
  22. 22. Contd.. <ul><li>Parenthesis(()):Indicates sub pattern </li></ul><ul><li>Ex. </li></ul><ul><li>w(oo)?d will search “wood” , “wd” </li></ul>
  23. 23. PHP PCRE FUNCTIONS <ul><li>preg_match() : Perform a regular expression match. </li></ul><ul><li>preg_match_all() : Perform a global regular expression match </li></ul><ul><li>preg_replace() : Perform a regular expression search and replace </li></ul><ul><li>preg_split() : Split string by a regular expression </li></ul><ul><li>preg_grep () : Return array entries that match the pattern </li></ul>
  24. 24. REFERENCE <ul><li>http://in.php.net/manual/ </li></ul>

×