0
Pattern p = Pattern.compile('\\((.*?)\\)');
string subject=  '( A  =  123 AND B  =  123 ) OR ( C  =  123 )' ;

Matcher matcher = p.matcher(subject);
system.debug(matcher.group(0));  // Saying no match found

I tried the regex here at http://regexr.com/ but it's not working.

3
  • you want something A = 123 AND B = 123 OR C = 123 in output? Commented Nov 25, 2016 at 10:43
  • I think you need to call matches() first to actually apply regular expression to string (like matcher.matches() ). documentation -- developer.salesforce.com/docs/atlas.en-us.apexcode.meta/…
    – kurunve
    Commented Nov 25, 2016 at 10:56
  • @Tushar sharma - I am expect to get value 1-> A =123 and B= 123 and value 2 -> c =123
    – bharath
    Commented Nov 25, 2016 at 11:19

1 Answer 1

1

Before you retrieve the group results, you must call find. Also I think 0 corresponds to the entire expression group, so you probably want group(1).

while (matcher.find()) system.debug(matcher.group(1));
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .