巷尾的酒吧

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            64 Posts :: 0 Stories :: 5 Comments :: 0 Trackbacks
          匹配數(shù)字和字母組合,數(shù)字和字母至少出現(xiàn)一次,只匹配1a,1q1,a1,a1a,1q2q2ws,w1w2e3r4r之類的,不匹配11,aa,a,1,"",這種的。
          package com.abin.lee.servlet.regex;
          import java.util.regex.Matcher;
          import java.util.regex.Pattern;
          public class MyRegex {
          public static boolean StringResult(String str)throws Exception{
          String regex="^(\\d+[a-z]+[0-9a-z]*)|([a-z]+\\d[0-9a-z]*)$";
          // String regex="^(\\d+[a-z]{1}[0-9a-zA-Z]*)|([a-z]+\\d[0-9a-zA-Z]*)$";
          Pattern pattern=Pattern.compile(regex);
          Matcher matcher=pattern.matcher(str);
          boolean flag=matcher.matches();
          return flag;
          }
          public static void main(String[] args) throws Exception{
          String str="aa1as12ds3232ds2d22";
          boolean result=StringResult(str);
          System.out.println("result="+result);
          }
          }
          posted on 2012-10-18 23:17 abing 閱讀(1081) 評論(1)  編輯  收藏 所屬分類: regex

          Feedback

          # 23434 2013-12-30 09:58 4324
          的撒旦  回復(fù)  更多評論
            

          主站蜘蛛池模板: 湘潭县| 武隆县| 江孜县| 察雅县| 淮滨县| 理塘县| 平潭县| 武清区| 沅江市| 卢龙县| 菏泽市| 庆阳市| 新乡县| 久治县| 新疆| 布拖县| 泾阳县| 巧家县| 保靖县| 万载县| 望奎县| 金华市| 肥东县| 伊金霍洛旗| 合作市| 罗田县| 土默特右旗| 通州市| 古交市| 习水县| 安远县| 明星| 罗山县| 呈贡县| 多伦县| 张家界市| 新竹县| 文成县| 康保县| 缙云县| 顺昌县|