My goal is a regex that captures {type} and {code} after propertyComplexity in the following string:-
/json/score/propertyComplexity/{type}/{code}
/json/score/propertyComplexity
(?<=propertyComplexity)\/(.*)\/|$
/json/score/propertyComplexity/{type}/{code}/{param3}/{param4}
/{(.*?)}/
You can use preg_match_all
combined with the following expression to achieve what you want:
/(?(?=^).*?propertyComplexity(?=(?:\/[^\/]+)*\/?$)|\G)\/\K([^\/]+)/
The '\G' assertion matches at the first position in the subject, which in this case effectively means that it matches at the position where the last match ended. The basic strategy here is to validate the format of the string at the beginning, then capture properties one at a time in subsequent rounds.
I'm not sure how strict you want to be with your validation, so I kept it quite simple.