JSFiddle - React, Tailwind, and code Playground

by jgarrido

JavaScript

const input = `467..114..
...*......
..35..633.
......#...
617*......
.....+.58.
..592.....
......755.
...$.*....
.664.598..`;

let lines = input.split('\n');
console.log(lines);

let numGrps = [];

lines.forEach((line, i) => {
	const matches = [...line.matchAll(/\d+/g)];
  // [...line.matchAll(regex)]
	matches.forEach((it) => {
		// const match = [i, it['index'], it[0], it[0].length];
    const match = {
    	row: i,
      pos: it['index'],
      val: it[0],
      len: it[0].length
    }
  	console.log(match);
  	numGrps.push(match);
  });
});

console.log("numGrps:", numGrps);