簡體   English   中英

從正則表達式中提取數字

[英]Extracting digits from a regular expression

var myString = 'Sent from your Zoom trial account - Your verification code is: 621226';
var regEx = /(\d+)$/g;
var result = regEx.exec(myString);

但是結果= [621226,621226]而不是[621226]

http://plnkr.co/edit/8ZbFHDAk0iLwEjpfkQaq?p=info

使用.match()regEx作為鏈接到myString參數。

 var myString = 'Sent from your Zoom trial account - Your verification code is: 621226'; var regEx = /(\\d+)$/g; var result = myString.match(regEx); console.log(result); 

plnkr http://plnkr.co/edit/cdwFsPKq9X3tCnub6FzL?p=preview

暫無
暫無

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

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