• Yogesh Singh 32
  • NEWBIE
  • 0 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 1
    Replies
I want to replace integers in "XYZ__3 AND XYZ__4" after size = 3 and expecting result "XYZ__4 AND XYZ__5"
 
String expression = 'XYZ__3 AND XYZ__4';
Integer size = 3;
Pattern p = Pattern.compile('(\\d{1,2})');
Matcher m = p.matcher(expression);

String next = '';
while (m.find()) {
   next = String.valueOf(size + 1);
   expression = expression.replaceAll(m.group(1), next);
   size++;
}

system.debug(expression);
But, I am getting "XYZ__5 AND XYZ__5". How can I achieve this using pattern and Matcher
 
I want to replace integers in "XYZ__3 AND XYZ__4" after size = 3 and expecting result "XYZ__4 AND XYZ__5"
 
String expression = 'XYZ__3 AND XYZ__4';
Integer size = 3;
Pattern p = Pattern.compile('(\\d{1,2})');
Matcher m = p.matcher(expression);

String next = '';
while (m.find()) {
   next = String.valueOf(size + 1);
   expression = expression.replaceAll(m.group(1), next);
   size++;
}

system.debug(expression);
But, I am getting "XYZ__5 AND XYZ__5". How can I achieve this using pattern and Matcher