I want to extract the text between the last ()
using javascript
For example
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
Method 1: Slicing and str. The simplest way to extract the string between two parentheses is to use slicing and string. find() .
Use %b() ( %b{} / %b[] for curly braces / square brackets): for s in string.
Try this
\(([^)]*)\)[^(]*$
See it here on 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, therefor you need to use match()[1]
to access the result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With