Re: reg-ex problem

From: Date: Thu, 08 Feb 2001 06:40:36 +0000
Subject: Re: reg-ex problem
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-38676@lists.php.net to get a copy of this message
Christian Reiniger wrote: > > On Wednesday 07 February 2001 21:50, Michael Dearman wrote: > > > } > > > elseif( preg_match( "/^\d+$/", $arg[$i], $matches ) ) > > > > Isn't this \d+ matching ----------^ > > > > > { > > > $value = $matches[0]; > > > } > > > elseif( preg_match( "/(div\d|prem)/", $arg[$i], $matches ) ) > > > > the \d in this-----------------^------------^ > > No. the 1st expression is /^\d+$/ , i.e. match strings with at least one > decimal number and nothing else (\d+) from their beginning (^) to their > end ($) > I.e. that one only catches strings consisting only of decimal digits. That's what I get for shooting my mouth off without actually trying it out. But I should of caught the ^$ > > > And the | is using '\d' and 'prem'. It probably should be > > "/(div\d)|prem/ Unless those parens are part of the expression. Then And after a second look, yea the \d is tightly bound to the div. But in confirming this, besides matching something like 'div2' it will also match div23 - both returning div2. Don't know the data, so it might not make any difference. Mike D.

« previous php.general (#38676) next »