1

I have this html tags:

</table>
   <p class="text_obisnuit2"><em>

I want to insert an html comments, so as to become:

</table>
  <!-- NEW TEXT -->  
   <p class="text_obisnuit2"><em>

I made a regex but is not working:

Find: (<\/table>)(\s+\S+)(<p class="text_obisnuit2"><em>)

Replace by: \1 <!-- NEW TEXT --> \3

2 Answers 2

1

Your regex can be improved like:

  • Ctrl+H
  • Find what: </table>(\R\h*)\K(?=<p class="text_obisnuit2"><em>)
  • Replace with: <!-- NEW TEXT -->$1
  • CHECK Wrap around
  • CHECK Regular expression
  • Replace all

Explanation:

</table>            # literally
(\R\h*)             # group 1, any kid of linebreak and 0 or more horizontal spaces
\K                  # forget all we have seen until this position
(?=<p class="text_obisnuit2"><em>)  # positive lookahead, make sure we have this text after

Replacement:

<!-- NEW TEXT -->   # new value to be inserted
$1                  # content of group 1, a linebreak and horizontal spaces

This keeps the linebreak and number of horizontal spaces from original text.

Screenshot (before):

enter image description here

Screenshot (after):

enter image description here

0
1

FIND: (</table>)(\r\s+)(<p class="text_obisnuit2"><em>)

REPLACE BY: \1\r\n\t <!-- NEW TEXT --> \r\n\t\3

or

FIND: (?s)(</table>)(.*)(<p class="text_obisnuit2"><em>)

REPLACE BY: \1\r\n\t <!-- NEW TEXT --> \r\n\t\3

or

If you have something like this:

</tr>
 </table>
 <p class="text_obisnuit2"><em>

FIND: (?s)(</tr>.*\K</table>)(.*)(<p class="text_obisnuit2"><em>)

REPLACE BY: \1\r\n\t <!-- NEW TEXT --> \r\n\t\3

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .