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;
        }

  • 相关阅读:
    Web后台项目学习2(代码部分)
    Web后台项目学习
    JDBC
    爬虫视频
    asyncio
    一篇做实验的随笔
    day14
    day13
    html+css 习题
    js-练习题
  • 原文地址:https://www.cnblogs.com/lexus/p/2382554.html
Copyright © 2011-2022 走看看