Home > OS >  mb_ereg_search_regs different behaviour with b option switching from php 7.4.7 to php 7.4.8
mb_ereg_search_regs different behaviour with b option switching from php 7.4.7 to php 7.4.8

Time:12-01

I have code like this:

$sTestString = "BEGIN:VEVENT";
$sPattern = '^(BEGIN|END)\:(. )$';
$sRegex_opt = 'mib';
mb_ereg_search_init( $sTestString );
print_r(mb_ereg_search_regs( $sPattern, $sRegex_opt ));

With PHP 7.4.7 I get

Array
(
    [0] => BEGIN:VEVENT
    [1] => BEGIN
    [2] => VEVENT
)

With PHP >= 7.4.8 I get an empty return value.

It seems to be tied to the "b" option. When i remove the "b" option i get the same result for all versions.

Can anybody explain what i am missing and why the behaviour changed?

I also looked into the mbstring git code and found the following change, could that be related?

https://github.com/php/php-src/commit/3f2f36d5d4c5c3c77703b366a5c7f9c3682727ee#diff-32e1239f9793b36003223e8568e0deeb803c42839195f48817b9f8deaf32a0b1

CodePudding user response:

Note that the b option used with mb_regex_set_options is meant to enable you to use the "POSIX Basic" regex flavor.

You do not actually have to parse the ^(BEGIN|END)\:(. )$ pattern with POSIX flavor, it is good enough to use the default.

Note that you do not need to escape the : char, it is not special, and you do not need the $ since . matches one or more chars other than line break chars as many as possible (so, all till the end of the line).

  • Related