Multiple HTML tag selection and delete with BBEdit Mac

1,012 views
Skip to first unread message

Nick A

unread,
Jun 2, 2010, 8:39:38 PM6/2/10
to BBEdit Talk
Hi everyone, thanks for your patience.

I am a sort-of beginner, really trying to take advantage of powerful
features to speed up work. I am re-designing for a guy with outdated
site; his site is a tangle of html tables used for styling and
layout.

I'm just smashing all the table tags so that I can keep his content
and re-style it with CSS once all the tables are gone. How do I select
all <table>,</table>,<tr>,</tr>,<td> and </td> at once and delete
them?

Thanks in advance,

Nick (who is trying to learn to work FAST)

Alex Satrapa

unread,
Jun 3, 2010, 12:13:28 AM6/3/10
to bbe...@googlegroups.com, BBEdit Talk
On 03/06/2010, at 10:39, Nick A <nicholasale...@gmail.com> wrote:

> I'm just smashing all the table tags so that I can keep his content
> and re-style it with CSS once all the tables are gone. How do I select
> all <table>,</table>,<tr>,</tr>,<td> and </td> at once and delete
> them?

Find (</?table|</?tr|</?td|</?tr)[^>]*> and replace with '' might work.

Alex Satrapa | web.mac.com/alexsatrapa | Ph: 0407 705 332

Kendall Conrad

unread,
Jun 3, 2010, 7:31:03 AM6/3/10
to BBEdit Talk
You'll want to make that less greedy (using *?) so it doesn't take out
too much. You can also simplify by moving the </? outside the
parentheses so it doesn't need to be repeated.

</?(table|tr|td)[^>]*?>

A little less readable, but we can move the 't' out as well.

</?t(able|r|d)[^>]*?>

-Kendall

On Jun 3, 12:13 am, Alex Satrapa <gr...@goldweb.com.au> wrote:

Gabriel Roth

unread,
Jun 3, 2010, 9:12:48 AM6/3/10
to bbe...@googlegroups.com
Nick—

In case you don't know: the suggestions from Alex and Kendall use grep, which is a powerful way of finding characters that match specified patterns. To use it, you'll want to enter the pattern in the 'Find' dialog and make sure that the 'grep' box is checked. 

For more information on grep, which is one of BBEdit's most useful tools, read chapter 8 in the BBEdit manual, available from the Help menu. It gives quite a good introduction.

gr.











--
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 bbe...@googlegroups.com
To unsubscribe from this group, send email to
bbedit+un...@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 "sup...@barebones.com" rather than posting to the group.

Ronald J Kimball

unread,
Jun 3, 2010, 11:44:11 AM6/3/10
to bbe...@googlegroups.com
On Thu, Jun 03, 2010 at 04:31:03AM -0700, Kendall Conrad wrote:
> You'll want to make that less greedy (using *?) so it doesn't take out
> too much. You can also simplify by moving the </? outside the
> parentheses so it doesn't need to be repeated.
>
> </?(table|tr|td)[^>]*?>

There is no need to use a non-greedy quantifier in this particular pattern.
[^>]*> and [^>]*?> are completely equivalent in what they will match.
Either way, you're matching exactly as many non-">" characters as there
are up to the first ">" character.

Ronald

Nick A

unread,
Jun 3, 2010, 12:10:39 PM6/3/10
to BBEdit Talk
I've looked into it a bit more and I've realized that I'm going to
need to get good at regular expressions to become a half-way decent
worker; they seem really powerful for automating monotonous tasks and
working quickly. Thanks for pointing me that way.

I tried Alex's suggestion and it picked up all the <table>,</
table>,<tr>,</tr>,<td> and </td> tags without picking up any others,
so it worked well.

Now I'm stuck with a search window that lists all the tags that were
found, but I don't know how to delete them all. Intuitively I want to
select all and delete, but it doesn't seem to work like that. Using
the find/find all/replace dialog box doesn't seem to be able to do it
all at once. How do I do this all at once? Thanks everyone. I'll refer
back to the more detailed GREP responses once I understand GREP a bit
better.

Nick

On Jun 3, 6:12 am, Gabriel Roth <gabe.r...@gmail.com> wrote:
> Nick—
>
> In case you don't know: the suggestions from Alex and Kendall use grep,
> which is a powerful way of finding characters that match specified patterns.
> To use it, you'll want to enter the pattern in the 'Find' dialog and make
> sure that the 'grep' box is checked.
>
> For more information on grep, which is one of BBEdit's most useful tools,
> read chapter 8 in the BBEdit manual, available from the Help menu. It gives
> quite a good introduction.
>
> gr.
>
> On Thu, Jun 3, 2010 at 7:31 AM, Kendall Conrad <angelw...@gmail.com> wrote:
> > You'll want to make that less greedy (using *?) so it doesn't take out
> > too much. You can also simplify by moving the </? outside the
> > parentheses so it doesn't need to be repeated.
>
> > </?(table|tr|td)[^>]*?>
>
> > A little less readable, but we can move the 't' out as well.
>
> > </?t(able|r|d)[^>]*?>
>
> > -Kendall
>
> > On Jun 3, 12:13 am, Alex Satrapa <gr...@goldweb.com.au> wrote:
> > > On 03/06/2010, at 10:39, Nick A <nicholasalexanderad...@gmail.com>
> > wrote:
>
> > > > I'm just smashing all the table tags so that I can keep his content
> > > > and re-style it with CSS once all the tables are gone. How do I select
> > > > all <table>,</table>,<tr>,</tr>,<td> and </td> at once and delete
> > > > them?
>
> > > Find (</?table|</?tr|</?td|</?tr)[^>]*> and replace with '' might work.
>
> > > Alex Satrapa | web.mac.com/alexsatrapa | Ph: 0407 705 332
>
> > --
> > 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 bbe...@googlegroups.com
> > To unsubscribe from this group, send email to
> > bbedit+un...@googlegroups.com<bbedit%2Bunsu...@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.

Matt Martini

unread,
Jun 3, 2010, 1:00:58 PM6/3/10
to bbe...@googlegroups.com
Nick,

If you are not afraid of the command line, you could do this in terminal:

     perl -pi.bak -e "s{</?t(able|r|d)[^>]*?>}{}gi"   filename.html

This will make the changes you want on filename.html and make a backup called filename.html.bak

Matt

please email "sup...@barebones.com" rather than posting to the group.

Ronald J Kimball

unread,
Jun 3, 2010, 1:09:48 PM6/3/10
to bbe...@googlegroups.com
On Thu, Jun 03, 2010 at 09:10:39AM -0700, Nick A wrote:
> I tried Alex's suggestion and it picked up all the <table>,</
> table>,<tr>,</tr>,<td> and </td> tags without picking up any others,
> so it worked well.
>
> Now I'm stuck with a search window that lists all the tags that were
> found, but I don't know how to delete them all. Intuitively I want to
> select all and delete, but it doesn't seem to work like that. Using
> the find/find all/replace dialog box doesn't seem to be able to do it
> all at once. How do I do this all at once? Thanks everyone. I'll refer
> back to the more detailed GREP responses once I understand GREP a bit
> better.

Just do a Replace All with the pattern in the Find field and nothing in the
Replace field.

Ronald

Robert A. Rosenberg

unread,
Jun 3, 2010, 1:12:08 PM6/3/10
to bbe...@googlegroups.com
At 9:10 AM -0700 on 06/03/2010, Nick A wrote about Re: Multiple HTML
tag selection and delete with BBEdit Mac:

>Now I'm stuck with a search window that lists all the tags that were
>found, but I don't know how to delete them all. Intuitively I want to
>select all and delete, but it doesn't seem to work like that. Using
>the find/find all/replace dialog box doesn't seem to be able to do it
>all at once. How do I do this all at once? Thanks everyone. I'll refer
>back to the more detailed GREP responses once I understand GREP a bit
>better.


I assume that you did a find to test the search. All you need to do
to actually delete them is to change your request from a find to a
find/replace and place a space in the replace box. This will remove
the tags and place a space where they were.

Bruce Van Allen

unread,
Jun 3, 2010, 1:41:58 PM6/3/10
to bbe...@googlegroups.com
On 2010-06-03, Nick A wrote:

>Now I'm stuck with a search window that lists all the tags that were
>found, but I don't know how to delete them all. Intuitively I want to
>select all and delete, but it doesn't seem to work like that. Using
>the find/find all/replace dialog box doesn't seem to be able to do it
>all at once. How do I do this all at once?

You need to study BBEdit more. There (of course) is a Replace
All command.

BUT before you do that...

What people have been suggesting is using the search pattern for
the table element markup and replacing each instance with '' -- nothing.

Before you do that, you might consider replacing table element
markup with some easily identifiable character(s), allowing you
to more easily see where the former table markup was, and also
use additional find/replace steps to begin putting your
non-table markup/css in place.

If I were dismantling tables with this brute force "I have to do
it fast" approach, perhaps not knowing for sure yet exactly how
the contents of the tables will be marked up in the new version,
I would at least throw in some white space. Something like
replacing <table> tags with two blank lines, <tr> tags with one
blank line, and <td> & <th> tags with a newline and a tab
(\r\t). That would at least let me see the what was left in
separate pieces.

You could just as easily replace <table> tags with <div> tags,
<tr> tags with <p>, and <td> & <th> with <span>. Taking this
further, try:
replace <table> tags with <div class="former_table">
replace <tr> tags with <p class="former_row">
replace <th> tages with <span class="former_heading">
replace <td> tags with <span class="former_cell">

You're not stuck forever with those classes named "former..." --
you can always do find/replace on them once the stuff being
marked up is integrated with your new css/markup scheme. In the
meantime, though, you have every piece of the former table's
content marked up with style-able structures.

But this really depends on whether the table's organization of
its contents maps closely to how you want to organize the
content in the new version. It probably won't map well, and
you'll have to do some hand work rearranging the content to work
with css layout. Then I think your job is simpler if you do
something like what I've suggested in above with white space.

HTH

- Bruce

_bruce__van_allen__santa_cruz_ca_

Gabriel Roth

unread,
Jun 3, 2010, 2:18:23 PM6/3/10
to bbe...@googlegroups.com
Hi Nick—

BBEdit comes with a useful tutorial, available through the Help menu. It covers the basics of grep searching and many other topics. Spending a couple of hours working through the tutorial will put you on a stronger footing with basic stuff like this, and will give you the terminology you need to look up the more complicated questions in the manual.

gr.




please email "sup...@barebones.com" rather than posting to the group.

Lorin Rivers

unread,
Jun 3, 2010, 2:39:27 PM6/3/10
to bbe...@googlegroups.com
On Thu, Jun 3, 2010 at 12:41 PM, Bruce Van Allen <b...@cruzio.com> wrote:
You need to study BBEdit more. There (of course) is a Replace All command.

BUT before you do that...

What people have been suggesting is using the search pattern for the table element markup and replacing each instance with '' -- nothing.

Before you do that, you might consider replacing table element markup with some easily identifiable character(s), allowing you to more easily see where the former table markup was, and also use additional find/replace steps to begin putting your non-table markup/css in place.

That is an EXCELLENT suggestion, Bruce! +1 

Alex Satrapa

unread,
Jun 3, 2010, 7:11:37 PM6/3/10
to bbe...@googlegroups.com, BBEdit Talk
On 04/06/2010, at 2:10, Nick A <nicholasale...@gmail.com> wrote:

> I've looked into it a bit more and I've realized that I'm going to
> need to get good at regular expressions to become a half-way decent
> worker; they seem really powerful for automating monotonous tasks and
> working quickly. Thanks for pointing me that way.

I recommend "Mastering Regular Expressions" - http://oreilly.com/catalog/9781565922570

Alex Satrapa | web.mac.com/alexsatrapa | Ph: +61 407 705 332

Nick A

unread,
Jun 10, 2010, 8:28:48 PM6/10/10
to BBEdit Talk
Thanks a lot. After looking at it all carefully, I'll go with the
white spaces. It's just the easiest to see but I won't have to re-
formulate more regexes to undo replacement tags i.e. divs. Now I guess
I move on to text factories so I can hit several files with this
approach.

On Jun 3, 10:41 am, Bruce Van Allen <b...@cruzio.com> wrote:
> On 2010-06-03, Nick A wrote:
>
> >Now I'm stuck with a search window that lists all the tags that were
> >found, but I don't know how to delete them all. Intuitively I want to
> >select all and delete, but it doesn't seem to work like that. Using
> >the find/find all/replace dialog box doesn't seem to be able to do it
> >all at once. How do I do this all at once?
>
> You need to study BBEdit more. There (of course) is a Replace
> All command.
>
> BUT before you do that...
>
> What people have been suggesting is using the search pattern for
> thetableelement markup and replacing each instance with '' -- nothing.
>
> Before you do that, you might consider replacingtableelement
> markup with some easily identifiable character(s), allowing you
> to more easily see where the formertablemarkup was, and also
> use additional find/replace steps to begin putting your
> non-tablemarkup/css in place.
>
> If I were dismantling tables with this brute force "I have to do
> it fast" approach, perhaps not knowing for sure yet exactly how
> the contents of the tables will be marked up in the new version,
> I would at least throw in some white space. Something like
> replacing <table> tags with two blank lines, <tr> tags with one
> blank line, and <td> & <th> tags with a newline and a tab
> (\r\t). That would at least let me see the what was left in
> separate pieces.
>
> You could just as easily replace <table> tags with <div> tags,
> <tr> tags with <p>, and <td> & <th> with <span>. Taking this
> further, try:
>    replace <table> tags with <div class="former_table">
>    replace <tr> tags with <p class="former_row">
>    replace <th> tages with <span class="former_heading">
>    replace <td> tags with <span class="former_cell">
>
> You're not stuck forever with those classes named "former..." --
> you can always do find/replace on them once the stuff being
> marked up is integrated with your new css/markup scheme. In the
> meantime, though, you have every piece of the formertable's
> content marked up with style-able structures.
>
> But this really depends on whether thetable'sorganization of

Gabriel Roth

unread,
Jun 10, 2010, 10:06:18 PM6/10/10
to bbe...@googlegroups.com
> Now I guess I move on to text factories so I can hit several files with this
> approach.

Actually, you can do that with the Multi-File Search command, in the
Search menu.

Reply all
Reply to author
Forward
0 new messages