|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75069 preg_match function wrong result
Submitted: 2017-08-13 13:07 UTC Modified: 2017-08-13 13:44 UTC
From: bublik dot drdrdr at gmail dot com Assigned:
Status: Not a bug Package: *Regular Expressions
PHP Version: 7.1.8 OS: Windows
Private report: No CVE-ID: None
 [2017-08-13 13:07 UTC] bublik dot drdrdr at gmail dot com
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);

Expected result:
array(0) { }

Actual result:
array(1) { [0]=> string(8) "вasdaв" }


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2017-08-13 13:14 UTC] 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
 [2017-08-13 13:44 UTC]
-Status: Open +Status: Not a bug
 [2017-08-13 13:44 UTC]
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.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jun 25 14:01:31 2024 UTC