date:\{\{birth date\|(\d+)\|(\d+)\|(\d+)
hegiht:(\d+)(\.\d+)?(in|inches|cm|\”)
public static void detectDates(String str) { String regex = "\\{\\{birth date\\|(\\d+)\\|(\\d+)\\|(\\d+)"; Pattern p = Pattern.compile(regex); Matcher matcher = p.matcher(str); while(matcher.find()) { for(int i=0;i<matcher.groupCount();) System.out.print(matcher.group(++i)+" "); System.out.println(); } } public static void detectLink(String str) { String regex = "\\[\\[([^\\|\\]]+)"; Pattern p = Pattern.compile(regex); Matcher matcher = p.matcher(str); while(matcher.find()) { for(int i=0;i<matcher.groupCount();) System.out.print(matcher.group(++i)+" "); System.out.println(); } } public static void detectNumber(String str) { String regex = "(\\d+)(\\.\\d+)?(in|inches|cm|\")"; Pattern p = Pattern.compile(regex); Matcher matcher = p.matcher(str); while(matcher.find()) { for(int i=0;i<matcher.groupCount();) System.out.print(matcher.group(++i)+" "); System.out.println(); } } public static void main(String[] args) { // TODO Auto-generated method stub String infor = "{{Infobox scientist"+ "| name"+ "= James Nicholas \"Jim\" Gray"+ "| birth_date = {{birth date|1944|1|12}}"+ "| birth_place = [[San Francisco, California]]"+ "| death_date = ('''lost at sea''')"+ "{{death date|2007|1|28|1944|1|12}}"+ "| nationality = American"+ "| field = [[Computer Science]]"+ "| alma_mater = [[University of California,"+ "Berkeley]]"+ "| advisor = Michael Harrison | height = 1.80cm | heigh = 1.2cm"; InfoBox.detectDates(infor); InfoBox.detectLink(infor); InfoBox.detectNumber(infor); } 输出: 1944 1 12 San Francisco, California Computer Science University of California,Berkeley 1 .80 cm 1 .2 cm
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263