开发者

Regular expression for string that starts with 'http://'

开发者 https://www.devze.com 2023-01-21 01:46 出处:网络
I need a regular expression that wi开发者_StackOverflowll match anything that starts with \'http://\'.Just look to see if the first 7 characters are "http://":

I need a regular expression that wi开发者_StackOverflowll match anything that starts with 'http://'.


Just look to see if the first 7 characters are "http://":

substr($url, 0, 7) == "http://"

There isn't any need for regular expressions here.


This will match everything up to the first whitespace: ^http://[^\s]*


This should do it: ^http://.*


So basically, if you want to match a URL in a string, use:

http://([-\w\.]+)+(:\d+)?(/([\w/_\.]*(\?\S+)?)?)?
0

精彩评论

暂无评论...
验证码 换一张
取 消