JSFiddle - React, Tailwind, and code Playground

JavaScript

str = "adfa odf 'aso'";
if(/(?:'[^']+'|"[^"]+")$/.test(str)){
    // alert('at the 2nd quote');
    res = str.replace(/(?:'[^']+'|"[^"]+")$/, "!string!");
    alert(res);
}