简体   繁体   English

将所有正则表达式匹配项放入数组中?

[英]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 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: 然后我有以下RegeX,应该将所有匹配项放在一个数组中:

$("#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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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