Regex must start with a letter or number, string can only have letters, numbers or slashes, and no double slashes

regex

Solution

You might try something like this (I hope whatever flavor you're using has lookahead!):

^(?!.*\/\/)[A-Za-z0-9][A-Za-z0-9\/]*$

Please see Regex 101 Demo for complete description and test strings.

Problem

I am trying to check some strings. Here are the parameters. - A string must start with a letter or number - A string can only contain letters, numbers or slashes - A string cannot have a double slash (ex: "api//go") Good Strings: ``` go go2/api/hello go/api45 ``` Bad Strings: ``` /go (can't begin with a slash) go//api (can't have a double slash) go/api% (can't contain non number, letter or slash) ``` I've been trying to use RegExr.com but to no avail. I have been trying with this expression: ``` ^[^\/](([0-9A-Za-z])+(\/)?)+ ``` but it does not quite work.

Original source