js 循环匹配 所有匹配项

    //正则表达式获取 所有的 @{}
    //匹配所有的 字符串 ,js 正则 并不能以此返回所有,,,,坑死了---
    var re=/@{([A-Z]{1})}/g;
    var arr=[];
    while(r = re.exec(editorText)) {   
        arr.push(r[1]);
    }  

类比java 区别:

/**
     * 
     * @param pstr
     *            正则表达式
     * @return 匹配数组
     */
    public static String[] findStr(String pstr, String value) {
        if (pstr == null || value == null || pstr.length() == 0 || value.length() == 0) {
            throw new RuntimeException("参数不能为空");
        }

        // "\@\{([A-Z]{1})\}"
        Pattern pattern = Pattern.compile(pstr);

        // String editorValue = "fsdfsdfsafsd@{A}fdsfd@{B}fsdfsd@{c}";
        Matcher matcher = pattern.matcher(value);

        List<String> list = new ArrayList<>();

        while (matcher.find()) {
            list.add(matcher.group(1));
        }
        String[] strings = new String[list.size()];
        return list.toArray(strings);
    }
原文地址:https://www.cnblogs.com/whm-blog/p/7273348.html