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

  • 相关阅读:
    中间键应用
    djano-cbv模式
    form表单使用(博客系统的登陆验证,注册)
    ajax-简介和实现注册登录
    django-settings.py配置
    Models-详细操作
    登陆验证系统实例-三种(cookie,session,auth)
    django-上传文件 fromdata(头像实例)
    学习笔记之CloudCompare
    学习笔记之Python 3
  • 原文地址:https://www.cnblogs.com/lexus/p/2382554.html
Copyright © 2011-2022 走看看