Reputation: 1966
I'm trying to write a regex that would match a URL with at least one capital letter into a capturing group.
Example:
/Hello-WoRLD
would match
/hellO/WoRld
would match
/foo/hello-WorLd/bar/baz/
would match
/this/url/is-in/all-lowercase
would NOT match
Basically any number of slugs with at least one capital letter would match.
I have the following regex that match for just one slug
^\/([a-zA-Z]*[A-Z]+[a-zA-Z]*)\/?$
But cant figure out how to match an indefinite number of slugs into the capturing group.
For context, I would rewrite this URL as /$1
to effectively rewrite all URL with capital letters to their lowercase counterparts.
Upvotes: 0
Views: 388
Reputation: 20747
This would do it:
^.*[A-Z].*$
And use \L$0
as the replacement.
https://regex101.com/r/aIqiKf/1
Upvotes: 1