Hi, I have been using a regular expression pattern to parse out links from a body of text, but have come into a bit of a problem, the pattern doesn't match links if they have bold (or any other) tags around them. Below is a small program to test the pattern:
namespace ConsoleApplication1 { public class RegTest { static void Main(string[] args) { string inText = "link 1 -
nobold test, link 2 - outBold, link 3 -
innerbold"; string Pattern = @"(?ixn-ms: (?[^""]+)""\s*>)(?[^<]+)(?) )"; MatchCollection Matches = Regex.Matches(inText, Pattern, RegexOptions.IgnoreCase); foreach (Match NextMatch in Matches) { Console.WriteLine(NextMatch.Groups["tag"].ToString());
Console.WriteLine(NextMatch.Groups["href"].ToString()); Console.WriteLine(NextMatch.Groups["content"].ToString()); Console.WriteLine(NextMatch.Groups["closetag"].ToString()); Console.WriteLine(); } Console.ReadLine(); } } } Any ideas on how I can modify this
regular expression so that it finds links with tags? And yes, regular expressions are a very weak point for me.
Oops, that code didn't come out quite right, let me try again: using System; using System.Text.RegularExpressions; namespace ConsoleApplication1 { public class RegTest { static void Main(string[] args) { string inText = "link 1 -
nobold test, link 2 - outBold, link 3 -
innerbold"; string Pattern = @"(?ixn-ms: (?[^""]+)""\s*>)(?[^<]+)(?) )"; MatchCollection Matches = Regex.Matches(inText, Pattern, RegexOptions.IgnoreCase); foreach (Match NextMatch in Matches) { Console.WriteLine(NextMatch.Groups["tag"].ToString());
Console.WriteLine(NextMatch.Groups["href"].ToString()); Console.WriteLine(NextMatch.Groups["content"].ToString()); Console.WriteLine(NextMatch.Groups["closetag"].ToString()); Console.WriteLine(); } Console.ReadLine(); } } }
I can't get this forum to pump out the code properly, there should be bold tags in the inText variable but it just makes the code bold.
Member
10 Points
7 Posts
Regular Expression help - parsing link tags
Oct 01, 2003 03:25 AM|benricho|LINK
Member
10 Points
7 Posts
Re: Regular Expression help - parsing link tags
Oct 01, 2003 07:19 PM|benricho|LINK
using System; using System.Text.RegularExpressions; namespace ConsoleApplication1 { public class RegTest { static void Main(string[] args) { string inText = "link 1 - nobold test, link 2 - outBold, link 3 - innerbold"; string Pattern = @"(?ixn-ms: (?[^""]+)""\s*>)(?[^<]+)(?) )"; MatchCollection Matches = Regex.Matches(inText, Pattern, RegexOptions.IgnoreCase); foreach (Match NextMatch in Matches) { Console.WriteLine(NextMatch.Groups["tag"].ToString()); Console.WriteLine(NextMatch.Groups["href"].ToString()); Console.WriteLine(NextMatch.Groups["content"].ToString()); Console.WriteLine(NextMatch.Groups["closetag"].ToString()); Console.WriteLine(); } Console.ReadLine(); } } }
I can't get this forum to pump out the code properly, there should be bold tags in the inText variable but it just makes the code bold.