If your only interest is in the home_dir, why bother capturing any of the text preceding it? You can use /([^/]*)$/ to capture all text following the last / character if that's all you're looking for. (Note: Regex not actually tested and may contain typos.)