Here you can find the source of getReplaceIndexes(String input, int startIndex, Stack
private static void getReplaceIndexes(String input, int startIndex, Stack<Integer> replaceStack)
//package com.java2s; //License from project: Open Source License import java.util.*; public class Main { private static void getReplaceIndexes(String input, int startIndex, Stack<Integer> replaceStack) { int idx = startIndex + 3; Stack<Character> stack = new Stack<>(); while (idx < input.length()) { switch (input.charAt(idx)) { case ')': if (stack.isEmpty()) { idx = input.length(); } else { stack.pop();//from w w w . java 2 s . c o m } break; case '(': stack.push('('); break; case '*': case '+': replaceStack.push(idx); break; case '|': if (stack.isEmpty()) { idx = input.length(); } break; } idx += 1; } } }