Is it possible to handle multiple regular expressions in PHP (or in general)?
I have the code below to replace non-alphanumeric characters with hyphens as soon as the replacement occurs. I want to delete instances of multiple dashes.
$slug = preg_replace('/[^A-Za-z0-9]/i', '-', $slug);
$slug = preg_replace('/\-{2,}/i', '-', $slug);
Is there an easier way to do this? those. install a regex pattern to replace one pattern and then another?
(I'm like a kid with a plug in a socket when it comes to regex)
source
share