0

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'

Thomas
  • 293
  • 1
  • 3
  • 15
  • 2
    Can you show us what you have tried so far? – Drew Kennedy Nov 26 '14 at 14:36
  • provide sample input and output, and what you've tried. – Jonesopolis Nov 26 '14 at 14:37
  • How certain are you that the urls will always end in .com? What about all the other domains (.net, .org, .biz, .pl, .se, .com.au, .com.na) – Bernd Linde Nov 26 '14 at 14:42
  • I edited the post to show the idea that I had but not sure how to implement it properly, @BerndLinde I am not sure, but I thought adding the other domains would be very complicated so I thought .com to start with – Thomas Nov 26 '14 at 14:44
  • possible duplicate of [C# regex pattern to extract urls from given string - not full html urls but bare links as well](http://stackoverflow.com/questions/10576686/c-sharp-regex-pattern-to-extract-urls-from-given-string-not-full-html-urls-but) – Bernd Linde Nov 26 '14 at 14:53
  • @BerndLinde Thanks that link was very helpful, I googled how to replace URLS and got stuff but not that, thanks for your help – Thomas Nov 26 '14 at 15:01
  • @BerndLinde However I do have one error in the code that I have edited into the post, If you could help with that – Thomas Nov 26 '14 at 15:07

0 Answers0