Re: Delete Entire Table Column

2010-03-21 Thread Bill Hernandez

On Mar 21, 2010, at 10:38 AM, Warren Michelsen wrote:

 Another grep question: How do I find, using grep, the third column within a 
 selected table? 
 
 I want to delete the third column in its entirety. The opening td and 
 closing /td may be on different lines. So, I need to find and select each 
 instance of tdSomeTextAcrossMultipleLines/td provided each such 
 occurrence is the third such occurrence following a tr.

Warren,

SEARCH : (tr[^]*)((td[^]*[^]+/td[\s]*){2,2})(td[^]*[^]+/td)
REPLACE : \1\2

(tr[^]*)
((td[^]*[^]+/td[\s]*){2,2})
(td[^]*[^]+/td)

line 4 traps for either :
tr
tr class=pred

lines 5, traps for any combination : 
td ... /tdtd ... /td
td ... /tdtd class=pblue ... /td

td class=pblue ... /tdtd class=pblue ... /td
td class=pblue ... /tdtd ... /td

This example has five columns, but you could have more (not valid html)

trtd column 1 /td 
td and column 2 /tdtd and 
column 3
/tdtd and column 4/tdtd column 5/td
/tr
tr class=predtd class=pblue column 1 /tdtd column 2 /tdtd and 
column 3
and more/tdtd column 4/tdtd column 5/td
/tr
trtd column 1/tdtdand column 2/tdtd and 
column 3
and more/tdtd class=pblue and 
column
4 and 
more/tdtd column 5/td
/tr

Will yield this (all column 3's are gone):

trtd column 1 /td 
td and column 2 /tdtd and column 4/tdtd column 5/td
/tr
tr class=predtd class=pblue column 1 /tdtd column 2 /tdtd 
column 4/tdtd column 5/td
/tr
trtd column 1/tdtdand column 2/tdtd and 
column
4 and 
more/tdtd column 5/td
/tr

Best of luck,

Bill Hernandez
Plano, Texas

-- 
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.

To unsubscribe from this group, send email to 
bbedit+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


Re: Delete Entire Table Column

2010-03-21 Thread Ronald J Kimball
On Sun, Mar 21, 2010 at 04:40:12PM -0500, Bill Hernandez wrote:
 
 On Mar 21, 2010, at 10:38 AM, Warren Michelsen wrote:
 
  Another grep question: How do I find, using grep, the third column within a 
  selected table? 
  
  I want to delete the third column in its entirety. The opening td and 
  closing /td may be on different lines. So, I need to find and select each 
  instance of tdSomeTextAcrossMultipleLines/td provided each such 
  occurrence is the third such occurrence following a tr.
 
 Warren,
 
 SEARCH : (tr[^]*)((td[^]*[^]+/td[\s]*){2,2})(td[^]*[^]+/td)
 REPLACE : \1\2
 
 (tr[^]*)
 ((td[^]*[^]+/td[\s]*){2,2})
 (td[^]*[^]+/td)

This solution makes a few assumptions that may not be valid.  It assumes
that none of the td tags will contain nested tags; that none of the td
tags will be empty; and that there will be no space between the tr and
the first td.

Here's an updated version of the regex.

Find

(tr[^]*\s*(?:td[^]*(?:(?!/td).)*/td\s*){2})td[^]*(?:(?!/td).)*/td

Replace

\1

The key here is the (?:(?!/td).)*, which will check to see if the next
thing in the string is /td, and if it's not, it will match one character,
then repeat that, matching one character at a time, until it gets to the
/td.

Ronald

-- 
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.

To unsubscribe from this group, send email to 
bbedit+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.


Re: Delete Entire Table Column

2010-03-21 Thread Warren Michelsen
At 7:30 PM -0400 3/21/10, Ronald J Kimball sent email regarding Re: 
Delete Entire Table Column:

On Sun, Mar 21, 2010 at 07:23:35PM -0400, Ronald J Kimball wrote:


 Find


(tr[^]*\s*(?:td[^]*(?:(?!/td).)*/td\s*){2})td[^]*(?:(?!/td).)*/td

 Replace

 \1



Oops, I forgot the (?s)...

(?s)(tr[^]*\s*(?:td[^]*(?:(?!/td).)*/td\s*){2})td[^]*(?:(?!/td).)*/td

Ronald


Alas, in a table with over 100 rows, BBEdit runs out of stack space:
out of stack space (application error code: 12246)
This happens with a Replace All and with repeated Replace and Find 
(one at a time).


--
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.

To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.


To unsubscribe from this group, send email to bbedit+unsubscribegooglegroups.com or reply 
to this email with the words REMOVE ME as the subject.


Re: Delete Entire Table Column

2010-03-21 Thread Ronald J Kimball
On Sun, Mar 21, 2010 at 06:40:39PM -0700, Warren Michelsen wrote:
 At 7:30 PM -0400 3/21/10, Ronald J Kimball sent email regarding Re: 
 Oops, I forgot the (?s)...
 
 (?s)(tr[^]*\s*(?:td[^]*(?:(?!/td).)*/td\s*){2})td[^]*(?:(?!/td).)*/td
 
 Ronald
 
 Alas, in a table with over 100 rows, BBEdit runs out of stack space:
 out of stack space (application error code: 12246)
 This happens with a Replace All and with repeated Replace and Find 
 (one at a time).

Unfortunately, that can happen in BBEdit with a sequence like (?:.)*
matching against a long block of text.  What version of BBEdit are you
running, by the way?

I'm afraid I don't have a recent version of BBEdit at hand to test with...
One of these might work better:

(?s)(tr[^]*\s*(?:td[^]*(?(?:(?!/td).)*)/td\s*){2})td[^]*(?(?:(?!/td).)*)/td

(tr[^]*\s*(?:td[^]*(?:(?!/td)|[^]+)*/td\s*){2})td[^]*(?:(?!/td)|[^]+)*/td

(tr[^]*\s*(?:td[^]*(?(?:(?!/td)|[^]+)*)/td\s*){2})td[^]*(?(?:(?!/td)|[^]+)*)/td

(?...) means once the subpattern has matched, don't backtrack into it to
try to match it differently.

Let us know how those work out for you.


Alternatively, the original regex does work in Perl.  :)

Ronald

-- 
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.

To unsubscribe from this group, send email to 
bbedit+unsubscribegooglegroups.com or reply to this email with the words 
REMOVE ME as the subject.