const regex = new RegExp('<span class="italics">([^<]*?)</span>', 'g')
const str = `What I am trying to do is to change all instances of <span class="italics">italicised text here</span> to <em>italicised text here</em> where the text in the middle changes throughout the document. I can't just find replace, because there are 598 instances of <span class="italics">, and 700 cases of </span>. Also, I want to learn how to do the find replace with leaving the stuff in the middle alone.
Do I use (.+?) at some point? I've been googling but unable to figure it out. Thank you in advance for your help!
Okay, your string finds the 598 I need to replace in my document, what can I add to the ([\\S\\s]*?) to get it to replace the span tags and leave the text between the span tags alone? For example, if it's <span class="italics">The New York Times</span> and <span class="italics">The Hitchhiker's Guide to the Galaxy</span>, is it possible to change those to <em">The New York Times</em> and <em>The Hitchhiker's Guide to the Galaxy</em> in one go, or do I have to do them individually?`;
const subst = `<em>\1</em>`;
// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);
console.log('Substitution result: ', result);
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions