private void replaceTemplates(String string) {
			StringBuilder buffy = new StringBuilder();
			StringBuilder templateBuffer = new StringBuilder();
			int depth = 0;
			for (int i = 0; i < string.length(); i++) {
				char c = string.charAt(i);
				if (c == '<') {
					if (depth == 0) {
						buffy.append(placeholderText);
					}

					templateBuffer.append(c);
					depth++;
					continue;
				}
				else if (c == '>') {
					templateBuffer.append(c);
					depth--;
					continue;
				}

				if (depth == 0) {
					buffy.append(c);
				}
				else {
					templateBuffer.append(c);
				}
			}

			modifiedText = buffy.toString();
			replacedText = templateBuffer.toString();
		}
A simple class to replace templates with a temporary placeholder value
Ghidra/Features/GnuDemangler/src/main/java/ghidra/app/util/demangler/gnu/GnuDemanglerParser.java