0

I'm trying to match a string that starts with either http:// or /.

This will pass...

http://www.google.com
/the/path/home.aspx

I'm pretty sure this will match http but I can't figure out how to fit in the optional /

/^(https?:\/\/)/i
4

3 回答 3

3

这应该有效:

/^((https?:\/)?\/)/i
于 2013-05-24T18:38:13.680 回答
2

您可以使用交替运算符( |),如下所示:

/^(\/|https?:\/\/)/i

更多细节在这里

于 2013-05-24T18:38:17.837 回答
2

使用符号 表示的“OR”运算符,如下所示|

/^(https?:\/\/|\/)/i
              ^^^
于 2013-05-24T18:38:22.330 回答