How to intercept irregular strings

for example, I have a dynamic string like 1232 {Button 1} {Button 2} 765432 (variable length). How can I get 1231 and {Button 1}, {Button 2}, 765432?

Mar.19,2021

const str = "1232{1}{2}765432";
function handleStr(str) {
  const result = [];
  //
  let inBraceNow = false;
  for (let i = 0; i < str.length; iPP) {
    const currentChar = str[i];
    if (inBraceNow) {
      result[result.length - 1] += currentChar;
      if (currentChar == "}") {
        inBraceNow = false;
      }
    } else {
        //"{"...
      if (currentChar == "{") {
        result.push("{");
        inBraceNow = true;
      } else {
          // result
          //0
        if (result.length == 0||(!+result[result.length-1])) {
          result.push(0);
        }
        result[result.length - 1] =10*result[result.length - 1]+(+currentChar);
      }
    }
  }
  return result;
}
console.log(handleStr(str));
Menu