|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-01-03 09:07 UTC] howachen at gmail dot com
Description:
------------
The mb_ereg_search() is regarding $ as end of line rather than end of string.
Reproduce code:
---------------
<?php
$str = " <div>apple\n </div> \n abc ";
$pattern = "^\s*<div>[\w\W]*?</div>\s*$";
print $str ;
mb_ereg_search_init($str, $pattern, "i");
if ( mb_ereg_search() ) {
$r = mb_ereg_search_getregs();
print_r($r);
do {
$cnt++;
$r = mb_ereg_search_regs();
}
while($r);
}
?>
Expected result:
----------------
Nothing
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 23:00:02 2025 UTC |
Using the default option (ONIG_OPTION_SINGLELINE | ONIG_OPTION_MULTILINE, i.e. 'sm' or 'p') or 's' it no matches, as you expect. Examples: <?php $str = " <div>apple\n </div> \n abc "; $pattern = '^\s*<div>[\w\W]*?</div>\s*$'; var_dump(mb_ereg_match($pattern, $str, 'p')); var_dump(mb_ereg_match($pattern, $str, 's')); var_dump(mb_ereg_match($pattern, $str, 'si')); var_dump(mb_ereg_match($pattern, $str, 'm')); var_dump(mb_ereg_match($pattern, $str, 'mi')); ?> oniguruma/doc/API says: ONIG_OPTION_SINGLELINE: '^' -> '\A', '$' -> '\z', '\Z' -> '\z' Although, IMHO, SINGLELINE was confused with MULTILINE in this extension. pcre.org/man.txt: \Z - matches at the end of the subject also matches before a newline at the end of the subject \z - matches only at the end of the subject Reclassified -> Doc. problem