gpt4 book ai didi

regex - 用于验证 URL 中的 '/' 的正则表达式

转载 作者:IT王子 更新时间:2023-10-29 02:29:59 27 4
gpt4 key购买 nike

我正在用 golang 编写一个网络应用程序。我正在使用正则表达式来验证 URL。但我无法在 URL 验证中包含“/”。

var validPath = regexp.MustCompile("^/(home|about)/(|[a-zA-Z0-9]+)$")

上面的 URL 使用 '/home/'、'/about/' 但不能用于 '/'。

谁能帮我解决这个问题?

最佳答案

为什么不添加这种情况作为替代:

"^/$|(/(home|about)/(|[a-zA-Z0-9]+)$)"

关于regex - 用于验证 URL 中的 '/' 的正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32022200/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com