I want to extract text between the last ()using javascript
()
for instance
var someText="don't extract(value_a) but extract(value_b)"; alert(someText.match(regex));
The result should be
value_b
thanks for the help
try it
\(([^)]*)\)[^(]*$
See here at regexr
var someText="don't extract(value_a) but extract(value_b)"; alert(someText.match(/\(([^)]*)\)[^(]*$/)[1]);
The part inside the brackets is stored in capture group 1, so you need to use it match()[1]to access the result.
match()[1]
/\([^()]+\)(?=[^()]*$)/
Appearance (?=[^()]*$)states that there are more parentheses before the end of input.
(?=[^()]*$)
.* (
.*
(
var str = "don't extract(value_a) but extract(value_b)"; var res = str.match(/.*\(([^)]+)\)/)[1]; console.log(res);
.*\(
([^)]+)
)
[1]
[\s\S]
.
Here is the demon in regex101
If the last closing bracket is always at the end of the sentence, you can use Jonathans answer. Otherwise, this might work:
/\((\w+)\)(?:(?!\(\w+\)).)*$/