JSFiddle - React, Tailwind, and code Playground

HTML

<div id="elem"></div>

JavaScript

var combinations = []

var map = ['*', '+', '{2,}', '{3,}', '{4,}']

for (var i = 0; i <= 4; ++i) {
    var a = 4 - i;
    for (var j = 0; j <= a; ++j) {
        var k = 4 - i - j;
        combinations.push([i, j, k])
    }
}

var array = ['\\w', '\\d\\w', '\\d\\w']

var expression = '/^' + combinations.map(function (comb) {
    var text = ''
    for (var i = 0; i < comb.length; ++i)
    text += array[i] + map[comb[i]]
    return text
}).join('|') + '$/'

var elem = document.getElementById('elem')
elem.innerHTML = expression