Regex to identify invalid URL slugs

I am struggling to find a regex that will identify invalid URL slugs. I often have revisions tasks where the translators add apostrophes or accented letters in the URL slugs and I keep removing them manually. I’d like to improve my workflow and spot the erroneous characters automatically.

A valid URL slug is composed of number, letters and hyphens (or underscore, depending on the chosen variant). Nothing else. Thus the regex for valid URL slugs is fairly simple: ^[a-z0-9]+(?:-[a-z0-9]+)*$

Now, where I am struggling is in negating this expression. I tried to use negative lookahead but it did not work. Any hint?

Philippe



Added the mention of "underscore"
[edited by: Philippe Noth at 6:57 PM (GMT 0) on 9 Feb 2023]
emoji