Moogal Moogal - 1 year ago 71
HTML Question

When doing a search I want to skip all code that ends in a closing tag

I have HTML that looks like this:

<td class="danish"> Det
tycker jag!</td>

I'm fixing the line break with this:

<td class="danish">(.*)

But sometimes the HTML ends in a tag on the same line:

<td class="danish">Det tyckeg jag</td>

I want it to skip lines like these when searching and find the next broken line.

In case anyone thinks it's just a frivolous thing to make the code look good, the rest of the code looks like this (not required reading):

<td class="danish"> Det
tycker jag!</td>
<?php audioButton("../../audio//det_lyder_godt","det_lyder_godt"); ?>

I ultimately have to take the text in the table and replace the one in the audiobutton a thousand times, but that's a different problem

Answer Source

I think this is what you're looking for:

(<td class="danish">(?:(?!</td>).)*)\r?\n\s*

This matches from <td class="danish"> to the next newline, unless there's a </td> tag first. Replace with "$1 " or "\1 " (without the quotes).

Using \r?\n instead of a literal newline makes the regex more robust. Even better is \R, if your regex flavor supports it.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download