code_junkie

Regular Expression nongreedy is greedy

Nov 12th, 2011
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.28 KB | None | 0 0
  1. tooooooooooooon
  2.  
  3. toooooooonoooooon
  4.  
  5. t.*n
  6.  
  7. toooooooonoooooon
  8.  
  9. t.*?n
  10.  
  11. toooooooon
  12.  
  13. $a = "toooooo";
  14. $b = "toooooon";
  15.  
  16. if ($a =~ m/(to*?)/) {
  17. print $1,"n";
  18. }
  19. if ($b =~ m/(to*?n)/) {
  20. print $1,"n";
  21. }
  22.  
  23. ~>perl ex.pl
  24. t
  25. toooooon
  26.  
  27. /o*?/
Add Comment
Please, Sign In to add comment