Edit report at https://bugs.php.net/bug.php?id=55654&edit=1
ID: 55654 Comment by: imaggens at gmail dot com Reported by: imaggens at gmail dot com Summary: ereg() behavior for preg_match Status: Open Type: Feature/Change Request Package: Regexps related Operating System: Windows 7 PHP Version: 5.3SVN-2011-09-09 (snap) Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2011-09-15 15:37:25] ni...@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