簡體   English   中英

將所有正則表達式匹配項放入數組中?

[英]Put all regex matches in an array?

我有一個輸入框,用戶可以在其中輸入如下數據:

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

然后我有以下RegeX,應該將所有匹配項放在一個數組中:

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




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

        })

但是我每次都只有一場比賽。 如何將所有匹配項放入數組中?

在正則表達式中添加/g修飾符:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM