zoukankan      html  css  js  c++  java
  • regex for java example


        public static String removeModelImpurities(String model)
        {
            Pattern regex = Pattern.compile("[^a-zA-Z0-9]$");
            String resultString = "";
            if (model!=null)
            {
                resultString=model.trim();
            }

            try {

                Matcher regexMatcher = regex.matcher(resultString);

                while(regexMatcher.find())
                {
                    try {
                        regexMatcher = regex.matcher(resultString);
                        try {
                            resultString = regexMatcher.replaceAll("");
    //                        System.out.println(resultString);
                        } catch (IllegalArgumentException ex) {
                            // Syntax error in the replacement text (unescaped $ signs?)
                        } catch (IndexOutOfBoundsException ex) {
                            // Non-existent backreference used the replacement text
                        }
                    } catch (PatternSyntaxException ex) {
                        // Syntax error in the regular expression
                    }
                    regexMatcher = regex.matcher(resultString);
                    if(resultString.length()==0)
                        break;
                }
            } catch (PatternSyntaxException ex) {
                // Syntax error in the regular expression
            }

            return resultString;
        }

  • 相关阅读:
    JavaScript 焦点事件
    在虚拟机里面运行java程序
    CentOS 7 命令
    修改和删除
    查询语句,查询指定的字段,带条件查询,排序查询
    Redis系列之-缓存的使用和优化
    Redis系列之-Redis-Sentinel
    Redis系列之主从复制原理与优化
    Redis系列之-使用常见问题
    Redis系列之-持久化
  • 原文地址:https://www.cnblogs.com/lexus/p/2382554.html
Copyright © 2011-2022 走看看