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?
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).