[UPHPU] regex help
Tyler Gee
geekout at gmail.com
Thu Mar 27 10:07:27 MDT 2008
On Thu, Mar 27, 2008 at 5:58 AM, Wade Preston Shearer
<lists at wadeshearer.com> wrote:
> I am trying to match both…
>
> http://example.com/a/b
>
> …and…
>
> http://example.com/a/b/
>
>
> ^(.*)/(.*)$
Regexp are greedy by default and they always return the first match,
so your first (.) will burn to the end of the string and then batch
the '/' and then there is nothing to match the (.*)$. The solutions
are mailed back just make the last '/' optional (0 or 1 occurence)
which means when the first regexp doesn't match, it tries again not
being greedy and this time matches the optional '/'
>
> …works for the first and…
>
> ^(.*)/(.*)/$
>
>
> …works for the second, but I can't find a solution that matches both.
> Shouldn't the first match both because I am stopping after the "b" and
> not caring about thing else after that?
>
> _______________________________________________
>
> UPHPU mailing list
> UPHPU at uphpu.org
> http://uphpu.org/mailman/listinfo/uphpu
> IRC: #uphpu on irc.freenode.net
>
--
~Tyler
More information about the UPHPU
mailing list