Here you can find the source of replace(String s, Properties p)
public static String replace(String s, Properties p)
//package com.java2s; /* //from w ww . jav a2 s. c o m * @(#)StringUtil.java 1.0 2004-10-11 * * Copyright 2005 UFIDA Software Co. Ltd. All rights reserved. * UFIDA PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. */ import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static String replace(String s, Properties p) { String regex = "\\$\\w+\\W|\\$\\{[^}]+\\}"; Pattern pattern = Pattern.compile(regex); Matcher m = pattern.matcher(s); while (m.find()) { String temp = m.group(); String key = null; if (temp.indexOf("{") != -1) { key = temp.substring(temp.indexOf("{") + 1, temp.length() - 1); } else { key = temp.substring(1, temp.length() - 1); } String value = p.getProperty(key); if (value != null) { s = s.replace(temp, value); m = pattern.matcher(s); } } return s; } }