-3

I am trying to extract a string from within a larger string where i need to get the value only inside the brackets.

var str = 'ajay kumar (68766)';
Thalaivar
  • 23,282
  • 5
  • 60
  • 71
  • http://stackoverflow.com/questions/17779744/regular-expression-to-get-a-string-between-parentheses-in-javascript – berentrom Feb 22 '14 at 17:32

2 Answers2

3

Try this:

var str = 'ajay kumar (68766)';
str = str.slice(str.indexOf('(')+1, str.indexOf(')'));
display-name-is-missing
  • 4,424
  • 5
  • 28
  • 41
0

How about using a regular expression?

var str = 'ajay kumar (68766)';
var output = str.replace(/^[\s\S]*?\((\d+)\)[\s\S]*?$/, '$1');
Toothbrush
  • 2,080
  • 24
  • 33