Java 正则 , 截取两个标签之间字符串 :
- String testStr = "12315<Test>show me</text>";
- Pattern p = Pattern.compile("<Text>(.*)</Text>");
- Matcher m = p.matcher(testStr);
- while(m.find()){
- System.out.println(m.group(1));
- }<span style="white-space: pre;"> </span>
- 如上, 控制台输出应为:show me.
实例://截取大串,循环取很多串
Pattern p = Pattern.compile("\\^G(.*)\\$"); //…^G 开始,$结尾
Matcher m = p.matcher(msg);
while(m.find()){
smlMsg=m.group(1);
gpsInfo = smlMsg.split("\\|"); // |分割
String st="";
for (int i = 0; i < gpsInfo.length; i++) {
if(i==0)
st="["+i+"]"+gpsInfo[i];
else
st=st+" "+"["+i+"]"+gpsInfo[i];
}
// createLog(ii,"\n=======================\n"+smlMsg+"\n=======================\n"+st);
}