正则表达式-------------------有条件替换
String str="02/S20080989 我国的犯罪分子日益猖獗应该加大打击力度 身份证:452324198003220911 驾证:贵60342343234 电话 0788-35532343 出入证:2323342553(高) 202,701"
要得到的串 为: S20080989 452324198003220911 贵60342343234 0788-35532343 2323342553(高)
数字连续长度要大于6
String ls_result
Pattern p = Pattern.compile("正则表达式 ");
Matcher m = p.matcher(str);
ls_result= m.replaceAll("")
=======================================
写了几个都不尽如人意.我是新手,水平有限,忘不吝赐教,100分 双手奉上!!
[解决办法]
public static void main(String[] args) { String str ="02/S20080989 我国的犯罪分子日益猖獗应该加大打击力度 身份证:452324198003220911 驾证:贵60342343234 电话 0788-35532343 出入证:2323342553(高) 202,701"; str = str.replaceAll( "^\\d+/([a-zA-Z]\\d+).*?:(\\d+[a-zA-Z]*).*?:(.\\d+).*?(\\d+-\\d+).*?:(\\d+\\(.\\)).*" , "$1 $2 $3 $4 $5" ); System.out.println(str); }
[解决办法]
String str="02/S20080989 我国的犯罪分子日益猖獗应该加大打击力度" + " 身份证:452324198003220911 驾证:贵60342343234 " + "电话 0788-35532343 出入证:2323342553(高) 202,701"; Pattern p=Pattern.compile("(S\\d*).*:(\\d*).*:(.\\d*).*?(\\d*-\\d*).*:(\\d*...)"); Matcher m=p.matcher(str); while(m.find()){ System.out.println(m.group(1)); System.out.println(m.group(2)); System.out.println(m.group(3)); System.out.println(m.group(4)); System.out.println(m.group(5)); }