I've done little with Regex, but I know this has to be simpler than I'm making it.
Given a URL that looks like this:
/p1/p2/{p3}/{p4}/.../{pn}
where {p3}
, {p4}
contain keys to an associate array.
I want to replace the values in the braces with the value in the braces (more specifically, a value in an associative array where this is the key)
So this ultimately becomes
/p1/p2/p3/p4
and ultimately /p1/p2/v3/v4
I suppose I could just replace the '{}'
with empty, but I want the replacement string to match the contents of the original expression exactly so the lookup in the array works.
I'm using the PHP function preg_replace
.
/(\w+)/({\w+})/
doesn't quite work...