JSFiddle - React, Tailwind, and code Playground

HTML

<div>
    <textarea rows="6" cols="50" id="myTextArea">
this is a test [1] also this [2] is a test
and again [18] this is a test. 
items[14].items[29].firstname too is a test!
items[4].firstname too is a test!
    </textarea>
</div>

<div>
   <button id="myButton">Try me</button>
</div>

JavaScript

var biggestNumber = function(str) {
    var pattern = /\[([0-9]+)\]/g, match, biggest = 0;

    while ((match = pattern.exec(str)) !== null) {
        if (match.index === pattern.lastIndex) {
            pattern.lastIndex++;
        }
        match[1] = parseInt(match[1]);
        if(biggest < match[1]) {
            biggest = match[1];
        }
    }
    return biggest;
}

document.getElementById("myButton").addEventListener("click", function() {
    alert(biggestNumber(document.getElementById("myTextArea").value));
});