Bug #75069 [Opn->Nab]: preg_match function wrong result
| From: | nikic@php.net | Date: | Sun, 13 Aug 2017 13:44:11 +0000 |
| Subject: | Bug #75069 [Opn->Nab]: preg_match function wrong result | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-210651@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75069&edit=1
ID: 75069
Updated by: nikic@php.net
Reported by: bublik dot drdrdr at gmail dot com
Summary: preg_match function wrong result
-Status: Open
+Status: Not a bug
Type: Bug
Package: *Regular Expressions
Operating System: Windows
PHP Version: 7.1.8
Block user comment: N
Private report: N
New Comment:
preg_match() is the correct function to use, you just need to specify the /u modifier if you're
working with UTF-8. Please do not recommend the use of mb_ereg_match() unless it is strictly
necessary.
Using "/(?=.*?[A-Za-z]).{8,}/u" will produce the desired result.
Previous Comments:
------------------------------------------------------------------------
[2017-08-13 13:14:48] spam2 at rhsoft dot net
can you tell why you are using preg_match() when you pretty clear deal with multibyte data to start
with? the 2 multibyte chars are 2 bytes and 6+2 = 8
http://php.net/manual/en/function.mb-ereg-match.php
------------------------------------------------------------------------
[2017-08-13 13:07:51] bublik dot drdrdr at gmail dot com
Description:
------------
preg_match finds a wrong match with these params:
pattern "(?=.*?[A-Za-z]).{8,}",
subject "вasdaв". Last contains 6 chars (english and russian), but regex pattern
must accept only 8+ chars.
Test script:
---------------
$out = array();
preg_match("/(?=.*?[A-Za-z]).{8,}/", "вasdaв", $out);
var_dump($out);
Expected result:
----------------
array(0) { }
Actual result:
--------------
array(1) { [0]=> string(8) "вasdaв" }
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75069&edit=1