【问题标题】:Regular expression for “Url Cannot start with www in prefix and white spaces“Url 的正则表达式不能在前缀和空格中以 www 开头
【发布时间】:2012-11-28 06:39:36
【问题描述】:

“Url 不能在前缀和空格中以 www 开头”的正则表达式 请帮助我。

eg:goole.com 是正确的

例如:www.google.com 不被接受

例如:不接受 www.google.com

前缀不是 www。而不是以空格开头-------->显示失败

googlewwwwwwwwww.com ---->显示成功

提前谢谢...

【问题讨论】:

标签: asp.net c#-4.0


【解决方案1】:

这是一个非正则表达式的解决方案。

string str = "goole.com";
Uri tempUri;
if (!str.StartsWith(" ") //shouldn't start with space
    && !str.StartsWith("www") //shoudn't start with www
    && Uri.TryCreate(str, UriKind.RelativeOrAbsolute, out tempUri) //should be 
                                                                   //a valid Uri
    )
{
    //valid url
}
else
{
    //invalid url
}

【讨论】:

  • 嗨 habib 我正在使用正则表达式前缀不应该 www。和空格,所以请帮助我并使用正则表达式
  • @user1858830,我不是正则表达式专家,你为什么不能在你的代码中使用这个检查?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-05-02
  • 2012-02-23
  • 2014-06-04
  • 1970-01-01
  • 1970-01-01
  • 2014-11-13
  • 2019-03-09
相关资源
最近更新 更多