From: "Morris, Chris" Date: 2002-04-27T00:20:39+09:00 Subject: RE: expand_path and overlap > I'm not sure, is this like what you want? > > def collapse_path(path, base) > head, = path.split("/", 2) > base.rindex(%r"(\A|.*/)#{Regexp.quote(head)}(?:/|\z)") > ($1 or base) + path > end Thanks! It seems to be close -- though I haven't groked it myself to see where it's breaking down. First unit test fails: assert_equal("/a/b/c", collapse_path("b/c", "/a/b/c/d/e")) expected: but was: Here are the other asserts I've got at the moment: assert_equal("/a/b", collapse_path("b", "/a/b/c/d/e")) assert_equal("/a/b/c/f", collapse_path("b/c/f", "/a/b/c/d/e")) assert_equal("/a/b/c/d/e/m/n/o", collapse_path("m/n/o", "/a/b/c/d/e")) assert_equal("/a/b/c/a/b/d", collapse_path("a/b/d", "/a/b/c/a/b/c")) Now that matz reminded me about rindex (i should've rtfm :), all these pass now with something I've written. It's not nearly as concise as your offering, Nobu, but I'm not much of a Regexp head, so I'm certainly interested in seeing a solution like yours. Chris