const spaceRegex = /<mspace\s+.*?\/>/
const answer = '<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>h</mi><mfenced><mi>x<mspace linebreak="newline"/></mi></mfenced><mo>=</mo><semantics><mrow><mo>-</mo><mn>3</mn></mrow></semantics><mspace linebreak="newline"/><mi>D</mi><mo>=</mo><mi mathvariant="normal">ℝ</mi></math>'
I have a regex to match <mspace .... />
, there are two matches in the above answer.
I want to replace the last match with <mspace width="10px"/>
So I want the output to be,
'<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>h</mi><mfenced><mi>x<mspace linebreak="newline"/></mi></mfenced><mo>=</mo><semantics><mrow><mo>-</mo><mn>3</mn></mrow></semantics><mspace width="10px"/><mi>D</mi><mo>=</mo><mi mathvariant="normal">ℝ</mi></math>'