Reputation: 7840
I am new in Regex can you please help in writing for regex in C# to extract url from text below?
Example 1
x+=1;
top.location.href = "http://www.keenthemes.com/preview/index.php?theme=metronic";
Example 2
alert("are you sure");
top.location.href = 'http://www.keenthemes.com/preview/index.php?theme=metronic';
Upvotes: 0
Views: 165
Reputation: 773
(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:/~\+#]*[\w\-\@?^=%&/~\+#])?
This will work for any kind of url. For more info please look at http://regexlib.com/Search.aspx?k=URL&AspxAutoDetectCookieSupport=1
Upvotes: 0
Reputation: 4960
If the URL always starts with http://
, this one should do it:
["'](http.*)["']
The URL is stored in the second group (Groups[1].Value
) of the Match
object
Upvotes: 1