logo       

non-greedy regexp: msg#01123

lang.ruby.general

Subject: non-greedy regexp

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?

Thanks

--
tom@xxxxxxxxxxxxxxxxxxx
remove 'spamfree.' to respond



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

News | FAQ | advertise