Regular expression in JavaScript *? With? Or * what's the difference?

The

* symbol selects 0 or one or more given expressions,
? 0 or one symbol selected,
*? This should be a non-greedy choice, with a single? Is there any difference?

const tags =  /^(area|base|br|col|embed|hr|img|input|keygen|link|menuitem|meta|param|source|track|wbr)$/i;
function convert(html) {
    return html.replace(
        /(<(\w+)[^>]*?)\/>/g, (all, front, tag) => {
            return tags.test(tag) ? all :
                front + "></" + tag + ">";
        });
}

this function is used to close non-auto-closing elements like < table/ >, but it doesn"t quite understand the author"s use of * in replace. Instead of?.


to understand greedy matching and non-greedy matching in the rule

conventional * and + are greedy matches
followed by ? is non-greedy matching *? +?

understand the following

'aaaaa'.match(/(a*?)(a*)/)
// 
["aaaaa", "", "aaaaa"]

'aaaaa'.match(/(a*)(a*?)/)
// 
[ "aaaaa", "aaaaa", "" ]
Menu