Regular Expression

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi,

I need to find the following and replace it using Regular Expression.

The text between those two tags can be anything, printable or unprintable,
and can be any length. Please help. Thanks.

<Info>whatever-include-unprintable-charasters</Info>
 
What are unprintable characters?
Anyways ... not a regex but you really don't need one for this:

string str = "<Info>whatever-include-unprintable-charasters</Info>";

int begin = str.IndexOf('>');
int end = str.LastIndexOf('<');

if (begin > -1 && end > -1)
{
begin += 1;
end -= begin;
str = str.Substring(begin, end);
}

Console.WriteLine( str );


HTH
 
Hi,

I need to find the following and replace it using Regular Expression.

The text between those two tags can be anything, printable or unprintable,
and can be any length. Please help. Thanks.

<Info>whatever-include-unprintable-charasters</Info>


Hello

string regex = @"<info>(?<Test>.*?)</info>";
Regex r = new Regex(regex);

MatchCollection mc = r.Matches( The src of the page or somting );
foreach (Match m in mc)
{
string TestText = m.Result("${Test}");

}

In every iteration you will have what you nee in TestText
.*? = To every thing
[A-Za-z0-9-]+ letter and numbers

Bast Regarts
Ohav Baumgarten
 
Back
Top