Reputation: 113
I'm working with next.js and I have a string (url). I need to check if the string contains at least 3x "/". Other chars are also present (letters, numbers and "-") - but they don't need to match something specific.
Example:
I think I need the following snippets:
I just don't know how to put them together in a regex. Could someone help me? Thanks a lot!
Upvotes: 0
Views: 105
Reputation: 163207
You can repeat the /
followed by the accepted characters 3 or more times.
Note that [A-Za-Z0-9]
should be [A-Za-z0-9]
instead.
^(?:\/[A-Za-z0-9-]+){3,}
To not match -
only, or at the start or end, you can optionally repeat it:
^(?:\/[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*){3,}
Upvotes: 4