How to extract text within all parentheses from a string in Node.js

2 Answers

0 votes
const str = "nodejs (600) php (programming) java ($1000000) c";
 
const regExp = /\(([^)]+)\)/g;
 
const matches = [...str.match(regExp)];
 
console.log(matches);
 
 
 
 
/*
run:
 
[ '(300)', '(programming)', '($1000000)' ]
 
*/

 



answered Dec 6, 2023 by avibootz
0 votes
const str = "nodejs (600) php (programming) java ($1000000) c";
 
const regExp = /\(([^)]+)\)/g;
 
const matches = [...str.matchAll(regExp)].flat();
 
for (let i = 0; i < matches.length; i++) {
    console.log(matches[i]);
}
 
 
 
 
/*
run:
 
(600)
600
(programming)
programming
($1000000)
$1000000
 
*/

 



answered Dec 6, 2023 by avibootz

Related questions

1 answer 151 views
1 answer 157 views
1 answer 134 views
1 answer 166 views
3 answers 440 views
...