I have a line like this
var msg = "ATEAM-3121 ATEAM-31 123 ATEAM-32 #finish \n ATEAM-3211 \n ATEAM-51 ATEAM-52 ATEAM-53 12345677 #finish ATEAM-1000";
In the line above, for each line, I would like to match tags matching ATEAM- [0-9] * before the #finish tag. If any line does not have # finish, all ATEAM tags should be ignored.
Here is an irregular solution that works
msg = msg.split("\n"); var tickets = []; msg.forEach(function(val) { var ticks = val.split(' '); for(var i = ticks.indexOf('#finish'); i >= 0; i-- ) { if(ticks[i].match(/^ATEAM-.*$/)) { tickets.push(ticks[i]); } } }); console.log(tickets);
But would like to convert it to a Regex solution, and this is what I tried
msg.match(/(ATEAM-[0-9]*|\
But this gives me the result, as in this fiddle , but its not as expected. Can someone help me with this?
source share