3
I have a string that has the format of routes:
/foo/
/{bar}/
/foo/{bar}
/{foo}/{bar}
/{foo}/bar/
Can have numerous values between bars, values between {}
are variable
I wanted to capture all occurrences of {qualquercoisa}
of these strings, for example:
/foo/{bar} => ["bar"]
/foo/bar => []
/{foo}/{bar}/ => ["foo", "bar"]
I tried with preg_match
, but I was only able to capture one incident:
preg_match("/\{([^\/]+)\}/", "/foo/{bar}/{baz}/", $match);
//$match = ["{bar}", "bar"]
preg_match("/(?:\{([^\/]+)\}\/?|[^\/]+\/?)+/", "/foo/{bar}/{baz}/", $match);
//$match = ["foo/{bar}/{baz}/", "baz"]
How to capture all occurrences?
What a mess to forget the
_all
, thanks for the help– Costamilam