Posted by Anno Siegel on 09/15/05 10:19
www.douglassdavis.com <doug@douglassdavis.com> wrote in comp.lang.perl.misc:
> I am using the preg_match function (in PHP) that uses perl regular
> expressions. Apparently I don't really understand regular expressions
> though. Could some one explain this?
>
> If this is the regular expression
>
> /^\s*(\d+\.\d+)|(\.\d+)|(\d+)\s*$/
>
> How does this:
>
> 40:26:46.302N 79:56:55.903W
>
> match? I thought when I added the ^ and $ that meant it had to match
> the whole thing? It seems to only be matching .302
Concatenation binds tighter than alternation. So the first alternative
is anchored to the left margin and the last one is anchored to the right
margin. The middle one isn't anchored and matched what it can.
Anno
--
If you want to post a followup via groups.google.com, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers.
[Back to original message]
|