简体   繁体   中英

Put all regex matches in an array?

I have an input box where a user can imput data like this:

528|438 530|438 528|439 532|439 533|438 534|438

Then I have the following RegeX, wich should put all matches in an array:

$("#offimportklik").click(function(){




            var teimporterendata = $("#importoffkader").val();
            var regex = /\d{1,3}\|\d{1,3}/;
            matches = teimporterendata.match(regex)
            alert(matches);

        })

But I only get one match every time. How do I put ALL matches in an array?

在正则表达式中添加/g修饰符:

var regex = /\d{1,3}\|\d{1,3}/g;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM