正则表达式:识别wiki中date、height、Link

发布时间:2024-11-20 07:52

讲座中如何识别并表达情绪 #生活技巧# #情绪管理技巧# #情绪管理讲座#

最新推荐文章于 2024-11-18 03:18:58 发布

qfzxhy 于 2016-12-25 12:03:53 发布


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

网址:正则表达式:识别wiki中date、height、Link https://www.yuejiaxmz.com/news/view/151232

相关内容

设计源·LINK创新
我是如何使用影石 Insta360 Link 教老人使用手机的?
html 日期 年月 年月日 及默认样式
link rel=alternate网站换肤功能最佳实现 « 张鑫旭
如何基于Linux SDK开发Link Visual视频设备的功能
基于OpenHarmony开发的健康生活应用(ArkTS)
【攻略资料分享】3DS幻想生活Link部分细节项目整理及汇总
有两个正弦量,其瞬时值的表达式分别为u=220JSin(ωt-10°)V,i=6
ViewPager不能高度自适应?height=wrap
【计算机视觉】基于Python—OpenCV的手势识别详解(一)

随便看看