Here is the solution I come up with after 30 minutes researching:
function wpse_175564() {
// The html goodies with shortcodes
$htmlcodes="<div class="akismet_activate">
<div class="aa_a">A</div>
<div onclick="document.akismet_activate.submit();" class="aa_button_container">
[the_shortcode id="4"]
<div class="aa_button_border">
<div class="aa_button">Activate your Akismet account</div>
</div>
</div>
<div class="aa_description"><strong>Almost done</strong>
- [the_shortcode id="4"] activate your account and say goodbye to comment spam</div>
</div>";
// End of HTML Goodies
// Let's get the shortcode inside the string and execute it!
$pattern = get_shortcode_regex();
if (preg_match_all( "https://wordpress.stackexchange.com/". $pattern .'/s', $htmlcodes, $matches ) && array_key_exists( 2, $matches )) {
foreach($matches[0] as $i => $v){
$htmlcodes = preg_replace($v , do_shortcode($v), $htmlcodes);
$htmlcodes = str_replace(array('[',']'), '', $htmlcodes);
}
}
return $htmlcodes;
}
Not sure whether that’s the best solution or not, but it works…!