HandyFile Find And Replace Online Help Submit feedback on this topic   

KB0003: How can I replace something within some tag

Question

How can I replace something within some tag for e.g. if I want to replace something within this tag <first> this is a test </first>.

I want the output which is <first> something </first>.

Answer

The solution is very simple. First, you have to match an opening tag:

\<tag_name[^\>]#\>

where [^\>]# means matching all tag until > is reached

then, match tag inner text:

[^\<]#

which means matching all tag inner text until < is reached

and the closing tag:

\<\/tag_name\>

The full search expression with () to store tags:

(\<tag_name[^\>]#\>)[^\<]#(\<\/tag_name\>)

Now, the replace expression:

\1something\2