- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
JavaScript RegExp return values between various square brackets? How to get value brackets?
Use regular expression with indexes 0,1….N to get the value without brackets. Following is the code −
Example
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]);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo132.js.
Output
This will produce the following output −
PS C:\Users\Amit\JavaScript-code> node demo132.js The first value without bracket=John Smith The second value without bracket=David Miller
Advertisements