string - How can I use javascript to get a substring of whatever is between two parenthesis? -


i trying return "aa" using javascript.

this doesn't work.

var mystr = "item code alpha tengo (aa)";  var newstr = mystr.substring("(",mystr.lastindexof(")")); 

you can do:

var mystr = 'item code alpha tengo (aa)'; mystr.replace(/^[^(]*\(|\)[^)]*$/g, ''); // aa 

or simpler:

mystr.replace(/.*\(|\).*/g,'') 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

Cross-Compiling Linux Kernel for Raspberry Pi - ${CCPREFIX}gcc -v does not work -

java.lang.NoClassDefFoundError When Creating New Android Project -