Jump to content

Need Regular Expression Help


javajoemorgan

Recommended Posts

Suppose I have a URL:[url="http://www.thisandthat.com/this/and/that"]http://www.thisandthat.com/this/and/that[/url]I want to capture everything after "http://www.thisandthat.com/", so that I have "this/and/that"However, the regular expression:"http://.*/(.*)"Captures "that" into $1. How do I make the first .* capture only up to the slash following the "www.thisandthat.com"?
Link to comment
Share on other sites

.* does its match in a "greedy" way, meaning that it will match as many characters as possible. So, in your example, the first .* matches "www.thisandthat.com/this/and". If you only want it to match up to the first slash, you'll want to do a "lazy" match.

"http://.*?/(.*)"

Link to comment
Share on other sites

Oh boy... wouldn't have guessed that...., but it is the solution... Thankx

.* does its match in a "greedy" way, meaning that it will match as many characters as possible. So, in your example, the first .* matches "www.thisandthat.com/this/and". If you only want it to match up to the first slash, you'll want to do a "lazy" match.
"http://.*?/(.*)"

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...