I want to select the contents of the second pair of parentheses in this string
"Hello my name is (john) (doe)."
How would I go about doing that? In addition, if there were an unknown number of pairs of parentheses, how would I be able to select the contents of the last one?
Here's a couple of possibilities. The first uses a regex to grab text between the last pair of parentheses (asserted using a lookahead that asserts there are no more opening parentheses after the last closing one), the second uses split, first on an opening parenthesis, grabbing the last value and then splitting that on a closing parenthesis and taking the first part of the result:
const str = "Hello my name is (john) (doe)."
result = str.match(/(?<=\()[^)]*(?=\)[^(]*$)/)[0]
console.log(result)
result = str.split('(').pop().split(')')[0]
console.log(result)