tags:

views:

54

answers:

4

Hi guys just like in the title - I need regular expression that will match anything that starts with 'http://'

+1  A: 

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

klausbyskov
@Gordon, it will do what the OP asked.
klausbyskov
+1  A: 

Is that really what you want?

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

Nev Stokes
Strictly speaking, the OP doesn't explicitly mention that it's a URI - he just wants to match *anything* that starts with 'http://'
Nev Stokes
+2  A: 

Why not just look to see if the first 7 characters are "http://"

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

No need for regexps here.

Paul
Agreed, but the OP asks for matches for anything that starts with 'http://', not for matches of http:// anywhere in the string.
Paul
Strpos will go off looking in the rest of the string too, so will be slower in non-matching cases :) We need the OP to tell us what's really needed.
Paul
+1  A: 

So basicly, you want to match a URL in a string?

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