JSFiddle - React, Tailwind, and code Playground

JavaScript

var s = "I am working on a problem where I need to be able to reverse a sentence but only words that are greater than 4 can be reversed.";

s2 = s.replace(/\b(\w\w\w\w\w+)\b/g, function(word) {
    return word.split("").reverse().join("");
});

console.log(s2);