crossma Posted July 9, 2003 Posted July 9, 2003 Hi, I am trying to figure out why this piece of code does not work: $pattern = "a{1,3}";$string = "aaaa"; if (!(eregi($pattern, $string))) { die ("Error: incorrect verse format"); } //Returns true The curly brackets are letting me match the least amount, but the upper bound is not containing my regular expression. Thanks in advance! Roy Thumbs Up Quote
surefire Posted July 9, 2003 Posted July 9, 2003 Regex expressions give me headaches... so I'll have to dust off my PHP Cookbook. I'll post what I find. Quote
surefire Posted July 9, 2003 Posted July 9, 2003 (edited) The best I've come up with so far indicates that you might want to try $pattern = "a{1,3}"; $string = "aaaaa"; if (!(eregi($pattern, $string)) || (strlen($string) > 3)) { die ("Error: incorrect verse format"); } //Returns true I know I 'cheated' a bit... but I think it might accomplish what you're looking for. I couldn't find the answer on the eregi function that I was looking for. I'm not an expert of eregi and perl-like matching... but I believe the results you were getting came from the server thinking: look for any pattern that is the lowercase 'a' either once, twice, or three times in a row. I'm not sure, but playing around with it seems to indicate that the pattern we've used doesn't eliminate patterns of four or more consecutive characters. I'm sure someone could come up with the eregi expression... but I've got a killer headache working now. Edited July 9, 2003 by surefire Quote
crossma Posted July 9, 2003 Author Posted July 9, 2003 Thanks Jack! I know what you mean about headache. The regular expression is the least of my programming for the day. I will go ahead and use the shortcut. Efficient regular expression programming can come another day. Roy Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.