JSFiddle - React, Tailwind, and code Playground

JavaScript

let texts = ["Invoice_001_1", "Invoice_001_2"];


var regTest = /(([a-zA-Z 0-9]+)_([0-9]+)_([0-9]+)$|[a-zA-Z ]+_([0-9]+)$)/gi;

for(var x=0; x<texts.length; x++) {
 		console.log(texts[x]);
		var matchReg = regTest.exec(texts[x]);
  	console.log(matchReg);
}