const regex = /Hello world!/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('Hello world!', 'gm')
const str = `STATISTICAL REPORTS OF MORBIDITY AND MORTALITY, STATES AND CITIES OF THE UNITED STATES UNTABULATED.
Arizona. — Quarter ended June 30, 1907. Estimated population, 122,931. Total number of deaths 292, including diphtheria 1, enteric fever 4, scarlet fever 11, smallpox 2, and 49 from tuberculosis.
Quarter ended September 30, 1907. Total number of deaths 402, including diphtheria 4, enteric fever 12, scarlet fever 2, smallpox 1, and 73 from tuberculosis. Cases: Diphtheria 26, enteric fever 79, measles 7, scarlet fever 34, smallpox 2, and tuberculosis 36.
Quarter ended December 31, 1907. Total number of deaths 505, including diphtheria 19, enteric fever 18, scarlet fever 1, and 161 from tuberculosis. Cases: Diptheria 85, enteric fever 49, measles 9, scarlet fever 20, smallpox 7, and tuberculosis 4.
California. — Month of December, 1907. Estimated population, 2,001,193. Total number of deaths reported to the State board of health, 3,484, including diphtheria 50, enteric fever 80, measles 6, scarlet fever 12, smallpox 1, plague 9, whooping cough 6, and 513 from tuberculosis.
Oakland. — Month of November, 11 1907. Estimated population, 225,000. Total number of deaths 169, including diphtheria 5, enteric fever 6, plague 1, and 13 from tuberculosis. Cases: Diphtheria 25, enteric fever 12, scarlet fever 7, smallpox 27, measles 5, plague 1, and tuberculosis 3.
Month of January, 1908. Total number of deaths not reported. Two deaths from diphtheria, 1 from enteric fever, and 11 from tuberculosis. Cases : Diphtheria 22, enteric fever 5, measles 6, scarlet fever 5, smallpox 24, and tuberculosis 8.
San Jose. — Month of January, 1908. Estimated population, 34,000. Total number of deaths, 39. Cases: Diphtheria 8, enteric fever 6, measles 2, scarlet fever 6, and smallpox 24.
Connecticut. — Stamford. — Month of December," 1907. Estimated population, 20,000. Number of deaths not reported. Cases: Diphtheria 2, enteric fever 3, measles 1, scarlet fever 4, and tuberculosis 3.
Received out of regular order.
205 February 21, 1908
Illinois — Alton. — Month of January, 1908. Estimated populations, 20,000. Total number of deaths, 15, including 4 from tuberculosis. Cases: Diphtheria 1.
Evanston. — Year ended December 31, 1907. Estimated population, 23,000. Total number of deaths, 268, including diphtheria 3, enteric fever 5, measles 1, whooping cough 4, and scarlet fever 4. Cases: Diphtheria 19, measles 128, scarlet fever 279, smallpox 2, and whooping cough 35.
Indiana. — Month of December, 1907. Estimated population, 2,648,594. Total number of deaths, 2,768, corresponding to an annual death rate of 12.1 per 1,000 of population, including 29 from diphtheria, 69 from enteric fever, 9 from measles, 8 from scarlet fever, 7 from whooping cough, and 315 from tuberculosis.
Morbidity : Diphtheria, 340 cases in 44 counties ; enteric fever, 318 cases in 47 counties ; smallpox, 218 cases in 19 counties.
Jefersonville. — Month of August, 1907. Estimated population, 10,840. Total number of deaths, 19, including 1 from tuberculosis. Cases: Enteric fever 10, diphtheria 1, and tuberculosis 2.
Month of September, 1907. Total number of deaths, 24, including 6 from tuberculosis.
Month of October, 1907. Total number of deaths, 8, including enteric fever 1, and 1 from tuberculosis. Cases: Diphtheria 3, enteric fever 3, and tuberculosis 1.
Month of November, 1907. Total number of deaths, 17, including enteric fever 2, and 2 from tuberculosis. Cases: Diphtheria 3, enteric fever 1, and tuberculosis 2.
Month of January," 1908. Total number of deaths not reported. One death from enteric fever and 2 from tuberculosis reported. Cases: Enteric fever 1 and tuberculosis 2.
Marion. — Month of January, 1908. Estimated population, 27,000. Total number of deaths, 20, including 2 from tuberculosis. Cases: Scarlet fever 1, diphtheria 1, smallpox 4, and tuberculosis 1.
Muncie. — Month ended February 4, 1908. Estimated population, 34,036. Total number of deaths, 23, including 2 from tuberculosis. Cases : Enteric fever 1, smallpox 1, and whooping cough 4.
Iowa. — Cedar Rapids. — Month of January, 1908. Estimated population, 30,000. Total number of deaths, 39, including enteric fever 2, scarlet fever 2, and 3 from tuberculosis. Cases: Scarlet fever 18, smallpox 4, and diphtheria 2.
Davenport. — Month of January, 1908. Estimated population, 40,000. Total number of deaths not reported. One death from diphtheria and 2 from enteric fever. Cases: Diphtheria 17, enteric fever 5, measles 2, scarlet fever 2, smallpox 1, whooping cough 2, and tuberculosis 1.
For month of December, 1907, see Public Health Reports, January 17, 1908.
.February 21 , 1908 206
Montana. — Month of December, 1907. Estimated population, 280,000. Keports to the State board of health show as follows : Total number of deaths, 373, including diphtheria 6, enteric fever 18, scarlet fever 5, and 1 from measles. Cases: Diphtheria 100, enteric fever 27, measles 19, scarlet fever 67, and smallpox 13.
Anaconda. — Month of December, 1907. Estimated population, 12,267. Total number of deaths, 20. Cases : Diphtheria 3 and measles 4.
Billings. — Month of December, 1907. Estimated population, 4,000. Total number of deaths, 18. Cases: Diphtheria 6, enteric fever 2, and measles 3.
Bozeman. — Month of December, 1907. Estimated population, 4,000. Total number of deaths, 9.
Butte.— Month of December, 1907. Estimated population, 43,624. Total number of deaths, 44, including enteric fever 1, measles 1, and 1 from scarlet fever. Cases: Diphtheria 16, enteric fever 2, measles 3, scarlet fever 4, and smallpox 1.
Great Falls. — Month of December, 1907. Estimated population, 21,500. Total number of deaths, 19, including 2 from scarlet fever. Cases: Scarlet fever 22.
Helena. — Month of December, 1907. Estimated population, 16,770. Total number of deaths, 18, including 2 from enteric fever. Cases: Enteric fever 1, measles 1, scarlet fever 7, and smallpox 2.
Livingston. — Month of December, 1907. Estimated population, 3,500. Total number of deaths, 6. Cases : Diphtheria 5.
Missoula. — Month of December, 1907. Estimated population, 5,000. Total number of deaths, 29, including 6 from enteric fever. Cases : Diphtheria 5, enteric fever 4, scarlet fever 2, and smallpox 3.
New Jersey. — Keports to the State board of health for the month ended January 15, 1908, show a total of 3,381 deaths, including diphtheria 70, enteric fever 49, measles 6, scarlet fever 39, whooping cough 7, and 326 from tuberculosis.
Morristovm. — Month of January, 1908. Estimated population, 12,500. Total number of deaths 22, including 1 from scarlet fever. Cases: Whooping cough 1, tuberculosis 2, and scarlet fever 16.
Paterson. — Month of October, 1907. Estimated population, 114,835. Total number of deaths 113, including diphtheria 1, enteric fever 1, and 10 from tuberculosis. Cases: Diphtheria 43, enteric fever 11, scarlet fever 30, and tuberculosis 5.
Month of November, 1907. Total number of deaths 139, including diphtheria 5, whooping cough 1, and 18 from tuberculosis. Cases: Diphtheria 49, enteric fever 8, scarlet fever 34, and tuberculosis 22.
Month of December, 1907. Total number of deaths 192, including diphtheria 3, enteric fever 1, scarlet fever 1, and 12 from tuberculosis.
207 February 21, 1908
Cases: Diphtheria 37, enteric fever 1, scarlet fever 59, and tuberculosis 12.
Phillipsburg. — Month of December, 1907. Estimated population, 13,500. Total number of deaths not reported. One death from diphtheria. Cases : Diphtheria 3, enteric fever 1, and scarlet fever 7.
Month of January, 1908. Total number of deaths not reported. Cases : Diphtheria 1 and scarlet fever 2.
New York. — Month of December, 1907. Estimated population, 8,227,000. Eeports to the State department of health show as follows: Total number of deaths 12,708, corresponding to an annual death rate of 18.5 per 1,000 of the population, including enteric fever 170, measles 138, scarlet fever 115, smallpox 1, whooping cough 35, diphtheria 243, and 1,218 from phthisis pulmonalis. Cases: Diphtheria 2,251, enteric fever 558, measles 3,831, scarlet fever 2,693 smallpox 167, and tuberculosis 2,065.
Buffalo. — Month of January, 1908. Estimated population, 400,000. Total number of deaths 539, including diphtheria 5, enteric fever 3, measles 4, scarlet fever 5, whooping cough 3, and 41 from tuberculosis. Cases: Diphtheria 51, enteric fever 20, measles 209, scarlet fever 138, whooping cough 50, smallpox 2, and tuberculosis 49.
Rochester. — Month of June, 1907. Estimated population, 200,000. Total number of deaths 233, including diphtheria 5, enteric fever 1, scarlet fever 1, measles 1, and 17 from tuberculosis. Cases: Diphtheria 29, enteric fever 7, and scarlet fever 57.
Month of July, 1907. Total number of deaths 201, including diphtheria 2, enteric fever 1, scarlet fever 1, measles 1, whooping cough 4, and 17 from tuberculosis. Cases: Diphtheria 17, enteric fever 12, and scarlet fever 30.
Month of August, 1907. Total number of deaths 278, including diphtheria 5, enteric fever 2, whooping cough 1, and 24 from tuberculosis. Cases: Diphtheria 18, enteric fever 23, and scarlet fever 16.
Month of September, 1907. Total number of deaths, 237, including diphtheria 5, enteric fever 4, whooping cough 3, and tuberculosis 21. Cases: Diphtheria 27, enteric fever 22, and scarlet fever 16.
Month of October, 1907. Total number of deaths, 240, including diphtheria 6, enteric fever 3, and 19 from tuberculosis. Cases : Diphtheria 49, enteric fever 19, and scarlet fever 32.
Month of November, 1907. Total number of deaths, 216, including diphtheria 4, enteric fever 3, whooping cough 2, and 19 from tuberculosis. Cases: Diphtheria 37, enteric fever 23, and scarlet fever 33.
Month of December, 1907. Total number of deaths, 222, including diphtheria 12, enteric fever 1, whooping cough 2, and 18 from
• February 21, 1908 208
tuberculosis. Cases: Diphtheria 42, enteric fever 13, and scarlet fever 46.
Schenectady. — Month of January, 1908. Estimated population, 77,666. Total number of deaths, 86, including diphtheria 3, and 1 from scarlet fever. Cases: Diphtheria 18, enteric fever 1, measles 6, scarlet fever 11, and smallpox 1.
Yonkers. — Month of January, 1908. Estimated population, 72,000. Total number of deaths, 99, including diphtheria 3, enteric fever 1, scarlet fever 4, whooping cough 1, and 15 from tuberculosis. Cases : Diphtheria 15, measles 9, scarlet fever 53, and phthisis pulmonalis 5.
Ohio — Ashtabula. — Month of January, 1908. Estimated population, 18,000. Total number of deaths, 33, including 1 from scarlet fever. Cases : Diphtheria 1, measles 7, and scarlet fever 5.
Pennsylvania — Dunmore. — Month of January, 1908. Estimated population, 17,500. Total number of deaths, 21, including 1 from tuberculosis. Cases: Scarlet fever 4, diphtheria 6, measles 4, and tuberculosis 1.
Homestead. — Twenty-four days ended February 7, 1908. Estimated population, 17,000. Total number of deaths, 38, including measles 1 and 4 from tuberculosis. Cases : Diphtheria 1, enteric fever 7, tuberculosis 1, and measles 30.
York.— Month of August, 1907. Estimated population, 49,000. Total number of deaths, 83, including diphtheria 2, enteric fever 2, whooping cough 2, and 4 from tuberculosis. Cases: Diphtheria 7, enteric fever 17, whooping cough 2, scarlet fever 1, measles 3, and tuberculosis 1.
Month of September, 1907. Total number of deaths, 66, including diphtheria 1, enteric fever 4, whooping cough 1, and 8 from tuberculosis. Cases : Diphtheria 7, enteric fever 18, measles 3, scarlet fever 3, and whooping cough 3.
Month of October, 1907. Total number of deaths, 46, including diphtheria 1, whooping cough 1, and 5 from tuberculosis. Cases: Diphtheria 17, enteric fever 10, measles 10, scarlet fever 2, whooping cough 5, and tuberculosis 2.
Month of November, 1907. Total number of deaths, 52, including diphtheria 1, enteric fever 1, and 3 from tuberculosis. Cases: Diphtheria 13, enteric fever 16, measles 34, and scarlet fever 2.
Utah — Ogden. — Month of January, 1908. Estimated population, 25,000. Total number of deaths, 63, including diphtheria 1, enteric fever 2, scarlet fever 2, and 3 from tuberculosis. Cases : Diphtheria 11, enteric fever 2, measles 25, scarlet fever 25, smallpox 13, and tuberculosis 3.
« Received out of regular order.
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions