using System;
using System.Collections;
using System.Text.RegularExpressions;
public class MyClass
{
public static void Main()
{
string stringToMatch = @"<p>new text
more text for version 2
An internal link to <a class=""internal"" href=""Show.aspx?PageName=Page+Name"">Page Name</a>.
An internal link to <a class=""create"" href=""Edit.aspx?PageName=A+Page"">A Page</a> that doesn't exist.
An external link to <a class=""external"" href=""http://localhost"">localhost</a>.</p>
<br/>
<br/>
<br/>
<p>some lines later, should be in a new paragraph.</p>
";
string pattern = @"(?<=<p(?:[\W\w]?)*?>)(?<Text>.[\w\W]*?)?(?=</p>)";
Regex r = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
int i = 0;
foreach(Match m in r.Matches(stringToMatch)){
Console.WriteLine(string.Format("------------BEGIN MATCH {0}------------", i));
Console.WriteLine(m.Value);
Console.WriteLine(string.Format("-------------END MATCH {0}-------------", i));
i++;
}
RL();
}
#region Helper methods
private static void WL(object text, params object[] args)
{
Console.WriteLine(text.ToString(), args);
}
private static void RL()
{
Console.ReadLine();
}
private static void Break()
{
System.Diagnostics.Debugger.Break();
}
#endregion
}
Microsoft (R) Visual C# .NET Compiler version 7.10.6001.4
for Microsoft (R) .NET Framework version 1.1.4322
Copyright (C) Microsoft Corporation 2001-2002. All rights reserved.
------------BEGIN MATCH 0------------
new text
more text for version 2
An internal link to <a class="internal" href="Show.aspx?PageName=Page+Name">Page Name</a>.
An internal link to <a class="create" href="Edit.aspx?PageName=A+Page">A Page</a> that doesn't exist.
An external link to <a class="external" href="http://localhost">localhost</a>.
-------------END MATCH 0-------------
------------BEGIN MATCH 1------------
some lines later, should be in a new paragraph.
-------------END MATCH 1-------------
Microsoft (R) Visual C# 2005 Compiler version 8.00.50727.42
for Microsoft (R) Windows (R) 2005 Framework version 2.0.50727
Copyright (C) Microsoft Corporation 2001-2005. All rights reserved.
------------BEGIN MATCH 0------------
new text
more text for version 2
An internal link to <a class="internal" href="Show.aspx?PageName=Page+Name">Page Name</a>.
An internal link to <a class="create" href="Edit.aspx?PageName=A+Page">A Page</a> that doesn't exist.
An external link to <a class="external" href="http://localhost">localhost</a>.
-------------END MATCH 0-------------
------------BEGIN MATCH 1------------
some lines later, should be in a new paragraph.
-------------END MATCH 1-------------