Regex to check with starts with http://, https:// or ftp://

后端 未结 5 1767
一个人的身影
一个人的身影 2020-12-28 12:59

I am framing a regex to check if a word starts with http:// or https:// or ftp://, my code is as follows,

     public          


        
5条回答
  •  时光说笑
    2020-12-28 13:23

    Unless there is some compelling reason to use a regex, I would just use String.startsWith:

    bool matches = test.startsWith("http://")
                || test.startsWith("https://") 
                || test.startsWith("ftp://");
    

    I wouldn't be surprised if this is faster, too.

提交回复
热议问题