读书人

提取月度

发布时间: 2013-11-08 17:52:14 作者: rapoo

提取月份

package regex;import java.util.regex.Matcher;import java.util.regex.Pattern;public class tiquMonth {public static void main(String[] args) {String regEx="([a-zA-Z]+)\\s+[0-9]{1,2},\\s*[0-9]{4}";String str="June 26, 1951";Pattern p=Pattern.compile(regEx);Matcher m=p.matcher(str);while(!m.find()){System.out.println("日期格式错误!");return;}System.out.println(m.group(1));System.out.println(m.group(0));//System.out.println(m.group(2));}}

?

执行后的结果为:

?June
June 26, 1951

?

读书人网 >移动开发

热点推荐