巷尾的酒吧

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            64 Posts :: 0 Stories :: 5 Comments :: 0 Trackbacks
          匹配數字和字母組合,數字和字母至少出現一次,只匹配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
          的撒旦  回復  更多評論
            

          主站蜘蛛池模板: 广宗县| 宜城市| 黄浦区| 永顺县| 舒兰市| 安宁市| 湟中县| 靖宇县| 浮梁县| 淳安县| 枝江市| 登封市| 马鞍山市| 枞阳县| 鄂伦春自治旗| 闽清县| 江都市| 化隆| 托里县| 上思县| 乌拉特中旗| 潮安县| 华安县| 睢宁县| 广灵县| 娄底市| 栾城县| 瑞金市| 乃东县| 广平县| 阳山县| 桐梓县| 巍山| 屏南县| 彭泽县| 从化市| 四会市| 开江县| 贵州省| 隆安县| 鹤峰县|