logo       

Re: non-greedy regexp: msg#01125

lang.ruby.general

Subject: Re: non-greedy regexp

On Tue, Aug 13, 2002 at 03:28:26AM +0900, Tom Robinson wrote:
> Hi,
>
> The following regexp is supposed to chop off the last / of a string
> and all characters following it, but it seems to be ignoring the
> non-greedy indicator (?):
>
> irb(main):001:0> "http://www.x.com/y/z.html".sub(%r|/.+?\.html$|, '')
> "http:"
>
> The expected result should be "http://www.x.com/y";. I thought this
> was a bug but perl produces the same result, so what am I missing?
>
> Is there a better alternative to doing url parsing by hand?

irb(main):001:0> "http://www.x.com/y/z.html".sub(%r|/[^/]+\.html$|,'')
"http://www.x.com/y";

--
_ _
| |__ __ _| |_ ___ _ __ ___ __ _ _ __
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

Never trust an operating system you don't have sources for. ;-)
-- Unknown source



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise