[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 509
  • Last Modified:

ASP.NET / VB / REGEX: Automatic Twitter Links

Using ASP,NET, VB and REGEX, I want to automatically create twitter links from this:
(@xyz) where xyz is the twitter username.

The problem with the code below is that it returns this:
<a href="http://twitter.com/(@WWF)">(@WWF)</a>.

instead of this:
(<a href="http://twitter.com/WWF">@WWF</a>).

input = RegularExpressions.Regex.Replace(input, "(?<!\S)(\(@\S+[^\s\)]+\S)", "<a href=""http://twitter.com/$1"">$1</a>")

Open in new window

0
hankknight
Asked:
hankknight
1 Solution
 
käµfm³d 👽Commented:
Try this:

input = RegularExpressions.Regex.Replace(input, "(?<!\S)\((@)(\S+[^\s\)]+)\)", "<a href=""http://twitter.com/$2"">$1$2</a>")

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now