JavaScript RegExp 如何在各種方括號間返回值?如何獲取值括號?
使用帶索引 0,1...N 的正則表示式獲取無括號的值。以下是程式碼 −
示例
var regularExpression= /(?<=\[).*?(?=\])/g;
var getTheValueWithIndex= "[John Smith][David
Miller]".match(regularExpression);
console.log("The first value without bracket="+getTheValueWithIndex[0]);
console.log("The second value without
bracket="+getTheValueWithIndex[1]);為執行以上程式,你需要使用以下命令 −
node fileName.js.
在此,我的檔名是 demo132.js。
輸出
這將產生以下輸出 −
PS C:\Users\Amit\JavaScript-code> node demo132.js The first value without bracket=John Smith The second value without bracket=David Miller
廣告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP