Using Java, I'm trying to write a regular expression that would parse another regular expression. I want to extract the named groups from the source regular expression (those represent parameters separated by slashes in an URL). Also, the source string may or may not start and end with a slash.
For example, for both source strings :
(?<name>john)/(?<facet>aaa/bbb/ccc/?)
and
/(?<name>john)/(?<facet>aaa/bbb/ccc/?)/
I'd like a regular expression that would extract those as named groups:
(?<name>john)
and (?<facet>aaa/bbb/ccc/?)
I tried :
(^|.*/)(?<param>\(\?<[^>]+>[^\)]+\))(/.*|$)
But this only returns (?<name>john)
as a group named "param", not (?<facet>aaa/bbb/ccc/?)
!!
When I remove the (/.*|$)
part, both are returned! But I want this ending condition to make sure a param is followed by a slash or is at the end of the line...
Do you have any idea why (/.*|$)
prevents the second param to be found?