JSFiddle - React, Tailwind, and code Playground

HTML

<textarea id="input">.coord('125','255')</textarea>
<button id="btn">Test Regex</button>
<textarea id="output"></textarea>

CSS

textarea, button{float:left;margin:10px auto;clear:both}
textarea{width:100%;min-height:80px}

JavaScript

$('#btn').click(function() {
    testReg($('#input').val(), $('#output'));
});

//array of regex pattern and replacement //just one for the example
var regexes = [ //FORMAT is array of [PATTERN,REPLACEMENT]
    /*.coord("X","Y")*/ [/\.coord\(['"]([\w]+)['"],['"]?([\w:\.\\]+)['"]?\)/g, '$1 * $2']
                  ];
function testReg(inputText, $output) {
    //using regex
    for (var i = 0; i < regexes.length; i++) {
        /*==>**1**/ //this one works as usual but dont let me get backreferences values
         //$output.val(inputText.replace(regexes[i][0], regexes[i][1]));

         /*==>**2**/ //this one should works as i understand it
         $output.val(inputText.replace(regexes[i][0], function(match, $1, $2, $3, $4) { 
            $1 = checkReplace(match, $1, $2, $3, $4);
            //here want using $1 modified value in replacement
            return regexes[i][1]; 
        }));

         /*==>**3**/ //this one is just a test by self call anonymous function
        // $output.val(inputText.replace(regexes[i][0], function(match, $1, $2, $3, $4) {
            //$1 = checkReplace(match, $1, $2, $3, $4);
            //here want using $1 modified value in replacement
            //return regexes[i][1];
        //}()));

        inputText = $output.val();
    }
}

function checkReplace(match, $1, $2, $3, $4) {
    console.log(match + ':::' + $1 + ':::' + $2 + ':::' + $3 + ':::' + $4);
    //HERE i should be able if lets say $1 > 200 divide it by 2
    //then returning $1 value
    if($1 > 200) $1 = parseInt($1 / 2);
    return $1; 
}