God of all wars
God of all wars

Reputation: 80

How to get only the content that is enclosed in parentheses of a string using regex?

I have a string that contains some values ​​in parentheses, and I would like to get only the first content that is within the first parenthesis with regex;

const str = "I (want to get this value), not this (value here)";
console.log(str)

Upvotes: 0

Views: 116

Answers (1)

Alireza
Alireza

Reputation: 2123

const regex = /(?<=\().*?(?=\))/;
const str = `I (want to get this value), not this (value here)`;
console.log(regex.exec(str)[0]);

Upvotes: 1

Related Questions