[uf-discuss] regexp for last path component

Geoffrey Sneddon foolistbar at googlemail.com
Sat Jun 7 12:51:46 PDT 2008


On 7 Jun 2008, at 16:48, Toby A Inkster wrote:

> Paul Denning wrote:
>
>> Can someone provide a regexp for the last path component?
>
>
> The following Perl-compatible regexp seems to do the trick:
>
> 	/^
> 	  [^\#\?]*         # Stuff at front (ignore)
> 	  \/([^\/]+)\/?    # Last path component
> 	  (\?.*)?          # Query string (ignore)
> 	  (\#.*)?          # Fragment (ignore)
> 	$/x
>
> Use the first sub-pattern match as the tag.

That seems to fall apart on "http://example.com" and "http://example.com/foo// 
". I tried to throw something together earlier: I couldn't manage  
without initially breaking it up into scheme/authority/path/query/ 
fragment, after which the following worked fine (on the path alone):

/
	\/([^\/\?\#]+)\/*
$/x


--
Geoffrey Sneddon
<http://gsnedders.com/>



More information about the microformats-discuss mailing list