正则+split 解决国航项目获取字符串匹配问题

需求:

有如下字符串信息:

-------SAVEANDSUBMIT页面TAIDsHID的值为:

00-NE8KF4P2-RC2Q-K4AM-AE78-PSUX1318YXP8;
5046860;
WF-D5DA47DD-1685-4EA0-9DDB-A5572A76CCE3;
4178072;


//目前提交值
00-NE8KF4P2-RC2Q-K4AM-AE78-PSUX1318YXP8;
5046860;
WF-70CA1C7E-F4CC-4280-94C9-21F79C456428;
4178081;

00-NE8KF4P2-RC2Q-K4AM-AE78-PSUX1318YXP8;
5046860;
WF-28883882-9EBC-4CB8-B166-AF50800E1B98;
4178060;

大致是这样的:

00-NE8KF4P2-RC2Q-K4AM-AE78-PSUX1318YXP8;5046860;WF-D5DA47DD-1685-4EA0-9DDB-A5572A76CCE3;4178072;00-NE8KF4P2-RC2Q-K4AM-AE78-PSUX1318YXP8;5046860;WF-70CA1C7E-F4CC-4280-94C9-21F79C456428;4178081;00-NE8KF4P2-RC2Q-K4AM-AE78-PSUX1318YXP8;5046860;WF-28883882-9EBC-4CB8-B166-AF50800E1B98;4178060;


我需要通过每段第三行的数获取第四行的activityID


我是这么解决的:

package com.airchina.client.test;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class TestString {
    public static void main(String[] args) {
    	String s="00-NE8KF4P2-RC2Q-K4AM-AE78-PSUX1318YXP8;5046860;WF-D5DA47DD-1685-4EA0-9DDB-A5572A76CCE3;4178072;00-NE8KF4P2-RC2Q-K4AM-AE78-PSUX1318YXP8;5046860;WF-70CA1C7E-F4CC-4280-94C9-21F79C456428;4178081;00-NE8KF4P2-RC2Q-K4AM-AE78-PSUX1318YXP8;5046860;WF-28883882-9EBC-4CB8-B166-AF50800E1B98;4178060;";
    	String t="WF-70CA1C7E-F4CC-4280-94C9-21F79C456428;";
    	String a="";
    	Pattern pattern = Pattern.compile(t+"\\d+;",Pattern.CASE_INSENSITIVE);
    	Matcher m = pattern.matcher(s); 
    	if(m.find()) {
    		System.out.println(m.group(0));
    		a=m.group(0);

    	}
    	String[] sPlit=a.split(";");
        a=sPlit[1];
        System.out.println(a);
    	
 		}
}

输出:

WF-28883882-9EBC-4CB8-B166-AF50800E1B98;4178060;
4178060



上一篇:C++之字符串分割函数split


下一篇:旋转动画用控件RotateView