JSFiddle - React, Tailwind, and code Playground

by humanzing

JavaScript

var r = /\[(\w*)\]/gm;
  let m;
    var real_int = 0;
    var result = [];
    while ((m = r.exec("text[lol]")) !== null) {
        if (m.index === r.lastIndex) {
            r.lastIndex++;
        }
        result.push(m.slice(0, m.length));
    }
    
    console.log(result)