PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/good/ext/pcre/tests/preg_match_all_edit_basic.php

http://github.com/facebook/hiphop-php
PHP | 55 lines | 45 code | 5 blank | 5 comment | 0 complexity | 5820cf8017c4b20a984b30f6cc58e6ad MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?hh
  2. /* Prototype : proto int preg_match_all(string pattern, string subject, array subpatterns [, int flags [, int offset]])
  3. * Description: Perform a Perl-style global regular expression match
  4. * Source code: ext/pcre/php_pcre.c
  5. * Alias to functions:
  6. */
  7. <<__EntryPoint>> function main(): void {
  8. $string = 'Hello, world! This is a test. This is another test. \[4]. 34534 string.';
  9. $match1 = null;
  10. var_dump(preg_match_all_with_matches(
  11. '/[0-35-9]/',
  12. $string,
  13. inout $match1,
  14. PREG_OFFSET_CAPTURE | PREG_PATTERN_ORDER,
  15. -10,
  16. )); //finds any digit that's not 4 10 digits from the end(1 match)
  17. var_dump($match1);
  18. $match2 = null;
  19. var_dump(
  20. preg_match_all_with_matches(
  21. '/[tT]his is a(.*?)\./',
  22. $string,
  23. inout $match2,
  24. PREG_SET_ORDER,
  25. ),
  26. ); //finds "This is a test." and "This is another test." (non-greedy) (2 matches)
  27. var_dump($match2);
  28. $match3 = null;
  29. var_dump(
  30. preg_match_all_with_matches(
  31. '@\. \\\(.*).@',
  32. $string,
  33. inout $match3,
  34. PREG_PATTERN_ORDER,
  35. ),
  36. ); //finds ".\ [...]" and everything else to the end of the string. (greedy) (1 match)
  37. var_dump($match3);
  38. $match4 = null;
  39. var_dump(
  40. preg_match_all_with_matches('/\d{2}$/', $string, inout $match4),
  41. ); //tries to find 2 digits at the end of a string (0 matches)
  42. var_dump($match4);
  43. $match5 = null;
  44. var_dump(preg_match_all_with_matches(
  45. '/(This is a ){2}(.*)\stest/',
  46. $string,
  47. inout $match5,
  48. )); //tries to find "This is aThis is a [...] test" (0 matches)
  49. var_dump($match5);
  50. }