I am trying to figure out how to look through a string which for now is called body
and it is set equal to the length of a text box, which can be any length between 0 - 1028
characters and replace any URLs.
The URLs could start with either of the following https
, http
, www.
ignoring case and would end in .com
The URLs ofc have no fixed length can anyone help me with this please
Edit: I haven't got much so far all I really have tried is this, with a for loop for each item in URLS, But I am not sure if this would work, or how to have the word.startsWith accept any of the www., http etc not just the specified one
var text1 = body;
var URLS = text1.Split(new[] { ' ' })
.Where(word => word.StartsWith("www."))
body = Regex.Replace(body, URLS[i], "<URL QUARANTINED>", RegexOptions.IgnoreCase);
string word2 = "";
Regex linkParser = new Regex(@"\b(?:https?://|www\.)\S+\b", RegexOptions.Compiled | RegexOptions.IgnoreCase);
string bodyString = body;
foreach (Match m in linkParser.Matches(bodyString))
body = Regex.Replace(bodyString, m, "URL QUARANTINED");
and the error I am getting is Error 2 Argument 2: cannot convert from 'System.Text.RegularExpressions.Match' to 'System.Text.RegularExpressions.MatchEvaluator'