473,387 Members | 1,365 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Regex Matching Q

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|Reg exOptions.IgnorePatternWhi
tespace|RegexOptions.Compiled);

No worky ...

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


Nov 18 '05 #1
2 1194
George Durzi wrote:
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|Reg exOptions.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\?>
--
mikeb
Nov 18 '05 #2
Thanks Mike,
That makes sense, I'll give that a shot

"mikeb" <ma************@mailnull.com> wrote in message
news:OT**************@TK2MSFTNGP10.phx.gbl...
George Durzi wrote:
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|Reg exOptions.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\?>
--
mikeb

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: aeuglein | last post by:
Hello! I have this RegEx: /(+:\/\/+)/i Now, I want to exlude on the end of a String the formats .gif / .jpg / ..png / .exe / .zip / .rar How I can this add to my regex ?
2
by: mikea59 | last post by:
I am getting errors in XMLSpy (Pro) in the following case: Source Document: <test> 12345 AB 12345 </test> Stylesheet: <xsl:stylesheet version="2.0"...
3
by: Day Of The Eagle | last post by:
Jeff_Relf wrote: > ...yet you don't even know what RegEx is. > I'm looking at the source code for mono's Regex implementation right now. You can download that source here ( use the class...
7
by: alphatan | last post by:
Is there relative source or document for this purpose? I've searched the index of "Mastering Regular Expression", but cannot get the useful information for C. Thanks in advanced. -- Learning...
7
by: bill tie | last post by:
I'd appreciate it if you could advise. 1. How do I replace "\" (backslash) with anything? 2. Suppose I want to replace (a) every occurrence of characters "a", "b", "c", "d" with "x", (b)...
5
by: Kofi | last post by:
Any takers? Got a string of DNA as an input sequence GGATGGATG, apply the simple regex "GGATG" as in Regex r = new Regex("GGATG", (RegexOptions.Compiled)); MatchCollection matches =...
8
by: Bob | last post by:
I need to create a Regex to extract all strings (including quotations) from a C# or C++ source file. After being unsuccessful myself, I found this sample on the internet: ...
7
by: CB | last post by:
Trying to match the entire following object literal code using a RegEx. var Punctuators = { '{' : 'LeftCurly', '}' : 'RightCurly' } Variations on the idea of using /var.*{.*}/ of course stops...
0
by: Tidane | last post by:
Visual Basic.NET Framework 2.0 I've created a program to parse out text as the program recieved it and use Regex matching to decide what should be done. My problem is that the text is matching when...
4
by: pedrito | last post by:
I have a regex question and it never occurred to me to ask here, until I saw Jesse Houwing's quick response to Phil for his Regex question. I have some filenames that I'm trying to parse out of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.