JSFiddle - React, Tailwind, and code Playground

JavaScript

var str = "BLAH BLAH BLAH copy 2";
var m = str.match(/^(.*?copy\s+)(\d+)$/i);
alert("Found '" + m[2] + "' at position " + m[1].length);