浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

i found the String.matches must match the whole string,could not match part of string

http://stackoverflow.com/questions/4771447/java-string-matches-regex-with-or-pipe

 

this is a trap

 

 

package ZZZZ;

import java.util.regex.PatternSyntaxException;

public class cc {


    public static void main(String[] args) {
       
        String subjectString="我__";
        // TODO Auto-generated method stub
        try {
            String regex="[^a-zA-Z0-9]*$";
           
            boolean foundMatch = subjectString.matches(regex);
            System.out.println(foundMatch);
        } catch (PatternSyntaxException ex) {
            // Syntax error in the regular expression
            System.out.println(ex.toString());
        }

    }

}

posted on 2012-03-04 09:28  lexus  阅读(261)  评论(0编辑  收藏  举报