I have a string of addresses:
let addr3 =
"123 Main Street St. Louisville OH 43071,432 Main Long Road St. Louisville OH 43071,786 High Street Pollocksville NY 56432,54 Holy Grail Street Niagara Town ZP 32908,3200 Main Rd. Bern AE 56210,1 Gordon St. Atlanta RE 13000,10 Pussy Cat Rd. Chicago EX 34342,10";
I want to use Regex with a lookahead and an exec function (I know there are different ways to do this, but I need to use these) to match each address line like the following:
['123 Main Street St. Louisville OH 43071,432',
'Main Long Road St. Louisville OH 43071,786',
'High Street Pollocksville NY 56432,54', ... ]
I put together the following Regex expression:
/(?:^|,\d+.|,\d+)(?=([^,]+,\d+))/;
While this expression matches each of the address string above when I use it in Rubular, when I attempt to run this from VScode in the following way:
let match;
const matches = [];
const pattern = /(?:^|,\d+.|,\d+)(?=([^,]+,\d+))/;
while ((match = pattern.exec(addr3))) {
matches.push(match[1]);
}
console.log(matches);
I get a FATAL ERROR and the text won't compile:
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Why will this regex combo work in Rubular, but not won't I run the exec loop, and how can I revise the code so that it will work properly?