Re: Invalid endpoint error on regular expression

From: Date: Fri, 10 Nov 2000 18:57:05 +0000
Subject: Re: Invalid endpoint error on regular expression
Groups: php.general 
Request: Send a blank email to php-general+get-24691@lists.php.net to get a copy of this message
Rod, Thanks so much. That's a great explanation of where I was going wrong and what regular expressions can do. You've put me on the right track. Seth ------Original Message------ From: "Rod Apeldoorn" <rod@islandnet.com> To: php-general@lists.php.net Sent: November 10, 2000 5:41:31 PM GMT Subject: Re: [PHP] Invalid endpoint error on regular expression "Seth Rothberg" <sethmr@bellatlantic.net> wrote in message news:382066129.973870165716.JavaMail.root@web622-wrb.mail.com... > Using php 3.x, I'm trying to build a regular expression with data gathered from > a submitted form. > > The code is in early days. Here it is: > $dateMask = "$startMonth_[$startDay-$endDay]_$startYear"; > > $dateMask will be a string that looks something like this: > 11_[12-18]_2000 > > Yet when I try to use $dateMask as a pattern for ereg: > if(ereg($dateMask, $file)) $calendar[] = $file; > > I get a warning message that I've got an invalid endpoint in the range. Looks > like a valid range to me. What am I missing? > --Seth Hey Seth, Regular Expressions are only really good for checking the format of the string, and not the data itself. Although it is possible to write an expression which does what you are looking for, it would be far easier if you extract the month and work with it in PHP. The reason why your expression failed (11_[12-18]_2000) was because the bracket sections are used to match individual characters, not integers. [0-9] would work because it would match a character valued between 0 and 9, but [12-18] would not. Here's a quick code snippet which does what I think you are looking for. It first verifies the Month_Day_Year format using a regular expression. Then it splits the data using "_" as the delimiter assigning the day to $fileDay. Only then does it check to ensure the day is between $startDay and $endDay. $dateMask = '^((0?[0-9])|(1[0-2]))_(([0-2]?[0-9])|(3[0-1]))_[1-2][0-9]{3}$'; if(ereg($dateMask, $file)) { list ($fileMonth, $fileDay, $fileYear) = split ('_', $file); if (($fileDay >= $startDay) && ($fileDay <= $endDay)){ $calendar[] = $file; } } Hope this helps! --- Rod Apeldoorn rod@canowhoopass.com http://www.canowhoopass.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#24691) next »