Well, this code of yours makes some very specific assumptions about the input string:
- /aa\n.*\n.*/g assumes, that every aa-line is followed by exactly 2 other lines which have to be extracted in addition to the aa-lead.
- /(aa.*).?(aa.*)/gs extracts exactly 2 fields from the string beginning with aa.
The regexes with look-ahead where proposed to cover a wider range of input strings.