Regex Matching Q

G

George Durzi

Consider the following HTML snippet. I want to extract the section shown
below.

<!-- some html -->
<TABLE WIDTH=100% CELLPADDING=0 CELLSPACING=0 border=0><?xml version=1.0
encoding=UTF-16?>
** There is some HTML here that I want to extract **
</TABLE>
<!-- some html -->

I did this:

Regex regex = new Regex(@<TABLE WIDTH=100% CELLPADDING=0 CELLSPACING=0
border=0><?xml version=1.0 encoding=UTF-16?>" + "((.|\n)*?)" + "</TABLE>",
RegexOptions.IgnoreCase|RegexOptions.Multiline|RegexOptions.IgnorePatternWhi
tespace|RegexOptions.Compiled);

No worky ...

Any idea what I'm doing wrong?
Am I building the regular expression correctly ?
 
M

mikeb

George said:
Consider the following HTML snippet. I want to extract the section shown
below.

<!-- some html -->
<TABLE WIDTH=100% CELLPADDING=0 CELLSPACING=0 border=0><?xml version=1.0
encoding=UTF-16?>
** There is some HTML here that I want to extract **
</TABLE>
<!-- some html -->

I did this:

Regex regex = new Regex(@<TABLE WIDTH=100% CELLPADDING=0 CELLSPACING=0
border=0><?xml version=1.0 encoding=UTF-16?>" + "((.|\n)*?)" + "</TABLE>",
RegexOptions.IgnoreCase|RegexOptions.Multiline|RegexOptions.IgnorePatternWhi
tespace|RegexOptions.Compiled);

No worky ...

Any idea what I'm doing wrong?
Am I building the regular expression correctly ?

Don't know if this is all that's wrong, but right off the bat you'll
need to escape the "?" characters that you're trying to match in the
"<?xml ... ?>" tag.

You should do the same for the "." character, even though it's probably
not the problem since it'll match the '.' in the target anyway.

So that part of the regex string might need to look like:

<\?xml version=1\.0 encoding=UTF-16\?>
 

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

Members online

No members online now.

Forum statistics

Threads
474,001
Messages
2,570,255
Members
46,853
Latest member
GeorgiaSta

Latest Threads

Top