Sử dụng biểu thức chính quy với các chỉ mục 0,1… .N để nhận giá trị không có dấu ngoặc. Sau đây là mã -
Ví dụ
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]);
Để chạy chương trình trên, bạn cần sử dụng lệnh sau -
node fileName.js.
Đây, tên tệp của tôi là demo132.js.
Đầu ra
Điều này sẽ tạo ra kết quả sau -
PS C:\Users\Amit\JavaScript-code> node demo132.js The first value without bracket=John Smith The second value without bracket=David Miller