从一字符串里找出符合条件的字符串.
字符串规则: $ + 一个单词 + { + 一系列字符 + }
比于:$word{abc=s123|cde=find|efg=www} 

解决方案 »

  1.   


    import java.util.regex.Matcher;
    import java.util.regex.Pattern;
    public class Test { public static void main(String[] args) {
    String testStr = "good$String{find|and$%h=+}substr**yes+_$String2${find2|***&%^hefdsa@h";
    findPatternStr(testStr); }

    /*
     *   @func:  查找符合要求的字符串
     *           规则: $ + 一个单词 + { + 一系列字符 + }如:$word{abc=s123|cde=find|efg=www}
     *   @param: str 进行匹配的测试字符串   
     *    
     */ public static void findPatternStr(String str) {

    String regStr = "\\$[a-zA-Z]+\\{.+\\}";                  
    Pattern p = Pattern.compile(regStr);
    Matcher m = p.matcher(str);
    while(m.find()){
    System.out.println("find the string:["+m.group()+"]");
    }
    }}