现在有个字符串是这样子的:http://${domain}${contextPath}${actionName}/${methodName}.${suffix}怎样才能用java语言得到${}中间的值,比如:domain
JavaString

解决方案 »

  1.   

    return 头像是你本人&&没对象?Call me:No way;
      

  2.   

    import java.util.regex.Matcher;
    import java.util.regex.Pattern;public class Hello {
        public static void main(String[] args) {
            String str = "http://${domain}${contextPath}${actionName}/${methodName}.${suffix}";
            Pattern pattern = Pattern.compile("\\$\\{(.*?)\\}");
            Matcher matcher = pattern.matcher(str);        while (matcher.find()) {
                System.out.println(matcher.group(1));
            }
        }
    }
    输出
    domain
    contextPath
    actionName
    methodName
    suffix