I’m looking to mine out some goodies from a multi-line string of text. I’m comfy doing regex in Perl (though I’m sure there is a better way than my code below), but don’t really see how to use a marked string in the regexp as part of the newSubStr in Javascript. Is there a way or am I stuck running multiple replaces on this to ditch the audio and source lines?
$_ = <<END;
<audio controls="controls" preload="metadata">
<source src="01.mp3" type="audio/mpeg">
<source src="01.ogg" type="audio/ogg">
Stuff
Default: <a href="01.mp3">>>download</a>
</audio>
END
s#.*<source.*?>.*?\n(.*)\n</audio>.*#$1#s;
print "[$_]\n";
Multiples regex in (my limited) Javascript might like this:
// We're really dependent on the HTML layout for line feeds
// so watch out.
var line = aElems[i].innerHTML.replace(/.*?audio.*?\n/gm, '');
var line2 = line.replace(/.*<source.*?\n/mg, '');
console.log(line2);
From reading both your questions it sounds like what you really want is to make the parent tag of your audio tag contain the innerHTML of your audio tag with the source elements removed.
A regexp would be error prone especially when you can use the DOM to get the same results with less effort.