troubleshooting Question

Need some RegExp help

Avatar of Batalf
BatalfFlag for United States of America asked on
PHP
4 Comments1 Solution206 ViewsLast Modified:
I need some help with a regexp challenge.

Based on some custom inserted tags in the HTML code, I need custom attributes into the <td> tags between these custom tags.

example:
[DEL] is the custom tag and it's ended with [/DEL]

So

[DEL]<td>test</td><td>More</td>[/DEL]

should become

<td diffMode="DEL">test</td><td diffMode="DEL">More</td>

Here's a more complex example which may help in testing.

This table:

<table>
      [DEL]
      <tr>
            <td>This is a cell</td>
            <td>This is another cell</td>
            <td>This is the third cell</td>
      </tr>
      [/DEL]
      <tr>
            [DEL]
            <td>This is also a cell</td>
            <td>Second cell on this row</td>[/DEL]
            <td>Last cell</td>
      </tr>
      [DEL]
      <tr>
            <td>New cell</td>
            <td>Cell</td>
            <td>Cell</td>
      </tr>
      <tr>
            <td colspan="2">New cell</td>
            <td>Another cell</td>
      </tr>
      [/DEL]
      <tr>
            <td>Cell</td>
            <td>Cell</td>
            <td>Cell</td>
      </tr>
</table>

Should after the regexp become like this:


<table>      
      <tr>
            <td diffMode="DEL">This is a cell</td>
            <td diffMode="DEL">This is another cell</td>
            <td diffMode="DEL">This is the third cell</td>
      </tr>      
      <tr>            
            <td diffMode="DEL">This is also a cell</td>
            <td diffMode="DEL">Second cell on this row</td>
            <td>Last cell</td>
      </tr>      
      <tr>
            <td diffMode="DEL">New cell</td>
            <td diffMode="DEL">Cell</td>
            <td diffMode="DEL">Cell</td>
      </tr>
      <tr>
            <td diffMode="DEL"> colspan="2">New cell</td>
            <td diffMode="DEL">Another cell</td>
      </tr>
      
      <tr>
            <td>Cell</td>
            <td>Cell</td>
            <td>Cell</td>
      </tr>
</table>

i.e. all the [DEL] tags are removed and instead, all <td> tags involved are tagged with the special attribute diffMode="DEL".

ASKER CERTIFIED SOLUTION
Join our community to see this answer!
Unlock 1 Answer and 4 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 4 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros