Nio Nio - 2 years ago 96
PHP Question

Regex to extract categories from URL

I have a Slug

and need a Regex to extract all category-segments (all segements after
) from this Slug.
The count of cataegory-segements may vary from zero to infinity.

I have already tried several ways but it never works as expected...
My last attempt was:


But this Regex returns just the last segment as match...
What can i do to get all categories?


Nio Nio
Answer Source

/(?:^aktuell\/blog|\G(?!^))(?:\/(\w+))/in combination with preg_match_all() works fine!

big thanks to @WiktorStribi┼╝ew and @SebastianProske

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download