preg_match_basic_edit.phpt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. --TEST--
  2. Test preg_match() function : basic functionality
  3. --FILE--
  4. <?php
  5. /* Prototype : proto int preg_match(string pattern, string subject [, array subpatterns [, int flags [, int offset]]])
  6. * Description: Perform a Perl-style regular expression match
  7. * Source code: ext/pcre/php_pcre.c
  8. * Alias to functions:
  9. */
  10. $string = 'Hello, world. [*], this is \ a string';
  11. var_dump(preg_match('/^[hH]ello,\s/', $string, $match1)); //finds "Hello, "
  12. var_dump($match1);
  13. var_dump(preg_match('/l^o,\s\w{5}/', $string, $match2, PREG_OFFSET_CAPTURE)); // tries to find "lo, world" at start of string
  14. var_dump($match2);
  15. var_dump(preg_match('/\[\*\],\s(.*)/', $string, $match3)); //finds "[*], this is \ a string";
  16. var_dump($match3);
  17. var_dump(preg_match('@\w{4}\s\w{2}\s\\\(?:\s.*)@', $string, $match4, PREG_OFFSET_CAPTURE, 14)); //finds "this is \ a string" (with non-capturing parentheses)
  18. var_dump($match4);
  19. var_dump(preg_match('/hello world/', $string, $match5)); //tries to find "hello world" (should be Hello, world)
  20. var_dump($match5);
  21. ?>
  22. --EXPECTF--
  23. int(1)
  24. array(1) {
  25. [0]=>
  26. string(7) "Hello, "
  27. }
  28. int(0)
  29. array(0) {
  30. }
  31. int(1)
  32. array(2) {
  33. [0]=>
  34. string(23) "[*], this is \ a string"
  35. [1]=>
  36. string(18) "this is \ a string"
  37. }
  38. int(1)
  39. array(1) {
  40. [0]=>
  41. array(2) {
  42. [0]=>
  43. string(18) "this is \ a string"
  44. [1]=>
  45. int(19)
  46. }
  47. }
  48. int(0)
  49. array(0) {
  50. }