C # Do you need to find web addresses using REGEX?
C # Do you need to find web addresses using REGEX?
Basically, I need to parse the string before uploading to WebBrowser
myString = "this is an example string http://www.google.com , and I need to make the link clickable";
webBrow.DocumentText = myString;
Basically, I want this to be a replacement for the web address, so that it looks like a hyperlink, and do this with whatever address is sucked into the string. I will need to replace the web address so that the web address reads like
<a href='web address'>web address</a>
This will allow me to have links available for interactive use. Any ideas?
This is possible depending on how strict or permissive you want your parsing to be.
As a first slice, you can try @"\bhttp://\S+"
, which will match any line starting with "http: //" on a word boundary (non-leading character such as space or punctuation).
To search using a regular expression and replace all occurrences with your own text, you can use the Regex.Replace method .
You can read The Elements of the Regular Expression Language to learn more.
source to share