JSFiddle - React, Tailwind, and code Playground

JavaScript

var val = 'HeLLo WOrld';
var ex = "replace(/s*/g,'-')";
 
var test = new Function('return val.' + ex + ';');
alert( test() );