const regex = /1/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('1', 'gm')
const str = `Telephone,Date,Zip
1-917-887-9281,08/02/2015,61022
1-614-122-0700,07/12/2013,51642
1-401-310-3354,04/07/2015,86161
1-776-738-7726,01/12/2014,61294
1-512-994-9175,02/02/2014,89104
1-401-546-6134,12/01/2014,89820
1-168-498-8484,21/06/2015,49526
1-778-253-5497,14/01/2015,98123
1-404-432-9739,10/09/2014,74122
1-629-563-3288,26/10/2013,47379
1-399-794-0834,21/05/2015,69891
1-210-801-0619,18/06/2015,79134
1-789-756-2201,10/07/2014,34644
1-673-598-4221,23/06/2015,89506
1-898-944-9344,02/05/2014,78701
1-401-926-2823,16/11/2014,38679
1-673-176-5233,03/09/2014,83277
1-670-119-0983,13/12/2013,44606
1-929-431-8036,21/06/2015,76118
1-941-986-2478,02/04/2014,38809
1-965-311-5298,13/02/2015,67390
1-966-241-2160,19/10/2014,12024
1-171-218-2878,16/05/2014,89757
1-579-696-3951,07/05/2015,88783
1-880-379-8249,27/05/2014,84169
1-729-730-5787,25/11/2014,50579
1-401-281-4234,28/01/2014,67149
1-136-687-0372,01/01/2015,88760
1-324-552-7773,06/12/2013,96232
1-460-954-6974,09/10/2014,44191
1-401-535-7233,17/12/2013,15725
1-177-661-0599,11/08/2015,58068
1-958-872-4163,14/02/2014,65903
1-751-976-1258,19/09/2015,33419
1-970-750-5604,08/03/2015,49727
1-401-311-1655,21/06/2015,16233
1-368-460-0652,14/04/2015,46683
1-561-904-8040,05/11/2013,84159
1-434-990-8299,19/01/2014,99741
1-405-919-6493,19/03/2014,92955
1-273-356-8382,03/03/2015,94595
1-969-466-0391,02/06/2014,28607
1-365-885-5483,09/07/2015,72921
1-479-782-0491,08/09/2015,90440
1-337-274-2635,09/01/2014,90487
1-126-912-0604,29/06/2015,77501
1-528-770-1186,16/10/2014,12597
1-251-239-7048,10/11/2013,56237
1-754-230-8264,16/11/2014,35546
1-257-642-5660,25/10/2014,86283
1-633-547-7089,26/04/2015,30792
1-161-604-0959,28/01/2015,83378
1-497-635-0092,26/07/2015,95635
1-926-635-0188,15/04/2014,95133
1-288-287-3450,08/06/2014,21739
1-981-694-3820,16/12/2014,12878
1-727-533-4754,23/05/2015,66255
1-310-697-1783,01/03/2014,94502
1-401-356-8358,10/11/2013,17172
1-264-760-2541,27/10/2014,61896
1-462-318-2842,14/12/2014,86195`;
// 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