正则表达式不好返回下标,字符串直接用indexOf不就行了
public static void main(String[] args){
String msg = "MESSAGE=rpd[1810]: %DAEMON-4: bgp_listen_accept: Connection attempt from unconfigured neighbor: 123.255.91.29+62490";
String reg = "DAEMON-4";//要匹配的字符串
int index = msg.indexOf("MESSAGE=");//获取下标
if(msg.indexOf(reg) >= 0){//如果存在
System.out.println(msg.substring(index+"MESSAGE=".length()));//截取字符串
}
}