我正试着检查一些字符串。这是参数。
好弦:
go
go2/api/hello
go/api45坏弦乐:
/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)我一直在尝试使用RegExr.com,但没有用。我一直在尝试这样的表达:
^[^\/](([0-9A-Za-z])+(\/)?)+但这不太管用。
发布于 2015-02-25 00:14:22
您可以尝试这样的方法(我希望您所使用的任何风味都具有前瞻性!):
^(?!.*\/\/)[A-Za-z0-9][A-Za-z0-9\/]*$请参阅 Regex 101演示 以获得完整的描述和测试字符串.
发布于 2015-02-25 00:14:14
给你:
^[0-9a-z](\/?[0-9a-z])*\/?$需要当前窗体中的/i (不区分大小写的修饰符)。这是相当简单的,不需要看头。
解释:
^ Starts with
[0-9a-z] 1 Alphanumeric character
( Start a repeatable group
\/? Optional /
[0-9a-z] 1 Alphanumeric character
)* Repeat the group zero or more times
\/? Allow for an ending slash
$ String must endhttps://stackoverflow.com/questions/28708711
复制相似问题