Req #55654 [Opn->Csd]: ereg() behavior for preg_match

From: Date: Thu, 28 May 2015 13:12:18 +0000
Subject: Req #55654 [Opn->Csd]: ereg() behavior for preg_match
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192971@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=55654&edit=1 ID: 55654 Updated by: cmb@php.net Reported by: imaggens at gmail dot com Summary: ereg() behavior for preg_match -Status: Open +Status: Closed Type: Feature/Change Request Package: Regexps related Operating System: Windows 7 PHP Version: 5.3SVN-2011-09-09 (snap) -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: Actually, your regex might match up to four decimal digits (\.[1-9][1-9]{1,3}). A probably suitable regex can be seen on <http://3v4l.org/GZ9MZ>. Anyhow, I'm closing this request, because I consider it highly unlikely and unnecessary that a simplified regex syntax will be made available for the PCRE implementation. Previous Comments: ------------------------------------------------------------------------ [2011-09-27 21:00:12] imaggens at gmail dot com Hi, Sorry for the long time to reply. I was unable to keep this task for a while. Where exactly you think should I add this lookahead assertion? As far as I know, it should be added one line after the last comment (the one which make all the floating part optional). But I have no success. As you said I can't match against start / end anchors because the float number may appear in several parts of input string. ------------------------------------------------------------------------ [2011-09-15 15:37:25] nikic@php.net I don't know what your exact use case is, but ... if you want to check that a string is a float, you should surround the regex with ^ and $ anchors. I.e. it will match the complete string, not just parts of it. ... if you are searching for floats in a longer text, you could simply use a negative lookahead assertion (?![0-9]) to ensure it isn't followed by a number. If neither are what you need, could you maybe explain your problem further? ------------------------------------------------------------------------ [2011-09-09 12:30:43] imaggens at gmail dot com Description: ------------ Consideration. I choosen "September Snapshot", because I could not find mine in the list. My installation report to "PHP 5.3.3. Build Date: Jul 21 2010 20:25:38". Alright. I would like to ask, if is there any possibility to add, maybe through another non-Perl compatible modifier, the behavior we had with ereg(). The behavior I'm talking about refers to match as much as possible instead of stop at very first valid match. This is useful sometimes. In my case, specially to validate input data against a RFC specification. Look at this snippet: https://ideone.com/sC6mA I tried to make it as much specific as I could. The intention was to validate float point numbers, between zero and 1, with none and up to three decimals, denying invalid floats, such as 0.00 (same as zero) or 1.0 (same as 1). But, the "lazy" behavior of preg_match() is accepting the code above, where 0.3444 should be denied, because of its 4 decimals. But since 0.344 is valid in the last length verification (one and up to three), the function accepts the input data, and the last digit is simply ignored, because preg_match() already caracterized 0.344 as valid. I hope you understand Expected result: ---------------- An empty array Actual result: -------------- A match ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55654&edit=1

« previous php.bugs (#192971) next »