Search code examples
htmlregexwordpresseditpad

Regular expressions to match several characters Editpad


I have a wordpress export with older posts which are going to be imported into a different installation. But I have an issue where there is a part of the content that needs to be converted into a different type of content in the other installation.

The original code is like this:

<a href="000d3c4c.mp3">000d3c4c</a>]]></content:encoded>

And I need to make it into this

	    </content:encoded><wp:postmeta>
		<wp:meta_key><![CDATA[mkd_post_audio_link_meta]]></wp:meta_key>
		<wp:meta_value><![CDATA[000d2aa8.mp3]]></wp:meta_value>
	</wp:postmeta>

I'm using EditPad Pro to search through the file, and to prevent me from using several hours doing this change manually, I tant to use the extensive search and replace feature in EditPad, but I have some issues trying to match this. I want an expression to be like this.

First search and replace will work no matter what because i can change

<a href="000

into

</content:encoded>
<wp:postmeta>
<wp:meta_key>
<![CDATA[mkd_post_audio_link_meta]]></wp:meta_key><wp:meta_value>><![CDATA[000d2aa8.mp3]]></wp:meta_value>
	</wp:postmeta>

But I struggle with the next part. How can I change everything after .mp3 to this

]]></wp:meta_value>
		</wp:postmeta>

To make it brief. I want to replace all occurences of

">000d3c4c</a>]]></content:encoded>

with

]]></wp:meta_value>
		</wp:postmeta>

The 000d3c4c are different for each occurence of the mp3 link.


Solution

  • Match this

    <a[^>]*>([^<]+)
    

    and replace by this

    </content:encoded>
    <wp:postmeta>
    <wp:meta_key><![CDATA[mkd_post_audio_link_meta]]></wp:meta_key>
    <wp:meta_value><![CDATA[$1.mp3]]></wp:meta_value>
    </wp:postmeta>