Regular Expression

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>
 
K

KH

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
 
O

Obaum1

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Regular Expression 1
regular expression 7
Regular expression 5
Regular Expression Help 1
regular expression NxM 9
Regular Expression? 3
One more regular expression 4
Regular Expression help 2

Top