473,378 Members | 1,527 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,378 software developers and data experts.

Regex help on a nested table.

I am trying to replace the nested table tag in the follow string[1]
using a regular expression, but I am not having any success. I am new
at using regular expressions, so I am sure I am just overlooking
something simple.

I thought <table.*>.*<table.*>.*</table> or some variation of that
would work to create a match, but it does not. Anyone have an idea as
to what would work?

[1]
<table *deleted attributes*>
<tr>
<td>
<table *deleted attributes*>
<tr>
<td><a>Nov</a></td>
<td>December 2003</td>
<td><a>Jan</a></td>
</tr>
</table>
</table>
Nov 15 '05 #1
2 2679
You need to use a backward-looking operator (there's a
much better jargon word for this which escapes me at the
moment).

*? will match as few characters as possible, so you
should be able to do this:

<table[^>]*>.*?<table[^>]*>.*?</table>

I have a feeling that this operator can cause performance
lag, but it should work fine in your situation.

I haven't tested the code, so give it a try -- did that
work?

JER

-----Original Message-----
I am trying to replace the nested table tag in the follow string[1]using a regular expression, but I am not having any success. I am newat using regular expressions, so I am sure I am just overlookingsomething simple.

I thought <table.*>.*<table.*>.*</table> or some variation of thatwould work to create a match, but it does not. Anyone have an idea asto what would work?

[1]
<table *deleted attributes*>
<tr>
<td>
<table *deleted attributes*>
<tr>
<td><a>Nov</a></td>
<td>December 2003</td>
<td><a>Jan</a></td>
</tr>
</table>
</table>
.

Nov 15 '05 #2

When you need the '.' to span multiple lines, use singleline mode. Try some
variation of this expression:

(?s)(?<=<table[^>]*>.*?)<table[^>]*>.*?</table>

The (?s) turns on the singleline option, which you could also do in code
like this:

Regex r = new
Regex(@"(?<=<table[^>]*>.*?)<table[^>]*>.*?</table>",RegexOptions.Singleline
);

The (?<=...) construct is a zero-width positive look-behind assertion,
which means "match this before what comes next, but don't include it in the
resulting match". Like the previous poster said, you also need to use lazy
quantifiers - *? - and negated character classes - [^>]. Lots of
big-sounding words and regex jargon here, but once you get a handle on it,
it offers a lot of power.
Brian Davis
www.knowdotnet.com

"Matt T." <go******@hotmail.com> wrote in message
news:f4**************************@posting.google.c om...
I am trying to replace the nested table tag in the follow string[1]
using a regular expression, but I am not having any success. I am new
at using regular expressions, so I am sure I am just overlooking
something simple.

I thought <table.*>.*<table.*>.*</table> or some variation of that
would work to create a match, but it does not. Anyone have an idea as
to what would work?

[1]
<table *deleted attributes*>
<tr>
<td>
<table *deleted attributes*>
<tr>
<td><a>Nov</a></td>
<td>December 2003</td>
<td><a>Jan</a></td>
</tr>
</table>
</table>

Nov 15 '05 #3

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

Similar topics

0
by: Dean H. Saxe | last post by:
I'm currently developing a tool in perl to search out potential XSS (Cross Site Scripting) vulnerabilities and correct them in a ColdFusion based web app. I've been having great success so far,...
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...
2
by: Tim Conner | last post by:
Hi, Thanks to Peter, Chris and Steven who answered my previous answer about regex to split a string. Actually, it was as easy as create a regex with the pattern "/*-+()," and most of my string...
1
by: Raghavendra Mahuli | last post by:
Hi group, I am using regular expression functions regex and regcmp to validate some record which are of the form- REC1{ 'Bsgf' | 'Cjsdg' | 78 } That is a fairly simple job. But i have to...
13
by: Chris Lieb | last post by:
I am trying to write a regex that will parse BBcode into HTML using JavaScript. Everything was going smoothly using the string class replace() operator with regex's until I got to the list tag....
4
by: Allen | last post by:
For my web-based php regex find/replace do-hickey, I need to match individual back references and wrap a tag around them so they'll be unique to the rest of the match for individual color markup. ...
7
by: MrNobody | last post by:
I'm trying to do some regex in C# but for some reason linebreaks are causing my regex to not work. the test string goes like this: string ss = "<tagname...
2
by: Shawn B. | last post by:
Greetings, Lets say I have the following expression: (<A|ABBR|ADDRESS|APPLET(\s){1,}(.*?)>(.*?)</A|ABBR|ADDRESS|APPLET) Such that it'll match any HTML tag that opens with the above specified...
2
by: mdaWeb335 | last post by:
Hi I'm trying to use RegEx to remove a tag by it's ID attribute. The actual HTML has already been cleaned up as I am formatting for export to Excel (so no need to point out that it's incorrect...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.