1
   

Regex search & replace to apply style to alternating TR rows

 
 
Monger
 
Reply Wed 17 Aug, 2005 10:46 am
The following regular expression search & replace function will apply an alternating class to every other TR row... e.g. it will turn this:
Code: <tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
<tr>
<td></td>
</tr>
...

into this:
Code: <tr class="odd">
<td></td>
</tr>
<tr class="even">
<td></td>
</tr>
<tr class="odd">
<td></td>
</tr>
<tr class="even">
<td></td>
</tr>
...


Here's the search & replace function... It works in Dreamweaver MX, but it will probably work as is or with slight modification in any application which supports regular expressions (e.g. EditPad, etc.):

Find in: Selected Text
Search: Source Code
Find: (<tr)([^>]*>[\S\s]*?</tr>[\S\s]*?<tr)([^>]*>[\S\s]*?</tr>)
Replace: $1 class="odd"$2 class="even"$3
Dreamweaver search options: Only 'Regular Expressions' should be checked


Figuring out a way to do this has saved me lots of time, so I just figured I'd pass it on.
  • Topic Stats
  • Top Replies
  • Link to this Topic
Type: Discussion • Score: 1 • Views: 2,149 • Replies: 1
No top replies

 
Craven de Kere
 
  1  
Reply Mon 22 Aug, 2005 05:46 pm
Nice! I'm adding this to my collection.
0 Replies
 
 

Related Topics

Perl - regular expression - Discussion by hoachen
 
  1. Forums
  2. » Regex search & replace to apply style to alternating TR rows
Copyright © 2024 MadLab, LLC :: Terms of Service :: Privacy Policy :: Page generated in 0.05 seconds on 12/27/2024 at 06:02:19