Posted by www.douglassdavis.com on 09/15/05 10:39
Anno Siegel wrote:
> 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.
>
That makes sense. Thanks. This seems to work:
/^\s*((\d+\.\d+)|(\.\d+)|(\d+))\s*$/
Navigation:
[Reply to this message]
|