zoukankan      html  css  js  c++  java
  • 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);
        }
  • 相关阅读:
    初识DJango框架
    web框架基础
    前端——JavaScript
    前端——css(下)
    前端——css(上)
    前端——html
    spring注解
    spring boot 详解(1)spring boot +mybatis+mysql+jsp
    spring 事务控制
    maven pom文件管理
  • 原文地址:https://www.cnblogs.com/whm-blog/p/7273348.html
Copyright © 2011-2022 走看看