JSFiddle - React, Tailwind, and code Playground

JavaScript

function matchToEnd(pattern, str) {
    var re = new RegExp(pattern.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&') + ".*"),
        result = str.match(re);
    if (result)
       return result[0];
    else {
       // didn't match, return default value of your choice, e.g.:
       return null;
    }
}

var result = matchToEnd("rgba(96, 16, 48, 0) 9px",
                        "rgba(96, 16, 48, 0) 9px #661133 10px rgba(96, 16, 48, 0) 11px");


alert(result);