The code below will get the text from within the brackets. The code makes use of some String methods
String eDescription = 'This is (the test) text';
Integer openingIndex = eDescription.indexOf('(');
Integer closingIndex = eDescription.indexOf(')');
String textInBrackets = eDescription.subString(openingIndex + 1, closingIndex);
Using @Sovereigntys suggestion of using substringBetween then the code becomes:
String eDescription = 'This is (the test) text';
String textInBrackets = eDescription. substringBetween('(', ')');
FYI: Both ways will find the first instance of '(' and ')'.
- Input: 'This is (the test) text', Output: 'the test'
- Input: 'This is (the test) (text)', Output: 'the test'