>> Even tried this to make sure I have only four last characters of my string.
>>
>> String endofMsg = sb.toString().substring(sb.toString().length() - 4);
>>
>> return endofMsg.matches("^\\r\\n|[\\n]##\\r\\n|[\\n]$");
>
> I found out I can do:
>
> String endofMsg = sb.toString().substring(sb.toString().length() - 6);
> return endofMsg.matches("\\r\\n##\\r\\n|.*\\n##\\n$");
>
> I had to use the last 6 characters since newline is different for each platform.
This seems to work:
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class EndTest {
private static final Pattern re =
Pattern.compile("^#\\d+\\v+(.*)##\\v+$", Pattern.MULTILINE +
Pattern.DOTALL);
public static void test(String s) {
System.out.println(s);
Matcher m = re.matcher(s);
if(m.find()) {
System.out.println("Match: " + m.group(1));
} else {
System.out.println("No match");
}
}
public static void main(String[] args) {
test("ABC");
String msg = "#877\r\n"
+
"<rpc-reply message-id=\"1\"
xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><data
xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\"><netconf-server
xmlns=\"urn:ietf:params:xml:ns:yang:ietf-netconf-server\"><listen><endpoint><name>default-ssh</name><ssh><tcp-server-parameters><local-address>0.0.0.0</local-address><keepalives><idle-time>1</idle-time><max-probes>10</max-probes><probe-interval>5</probe-interval></keepalives></tcp-server-parameters><ssh-server-parameters><server-identity><host-key><name>default-key</name><public-key><keystore-reference>genkey</keystore-reference></public-key></host-key></server-identity><client-authentication><supported-authentication-methods><publickey/><passsword/><other>interactive</other></supported-authentication-methods><users/></client-authentication></ssh-server-parameters></ssh></endpoint></listen></netconf-server></data></rpc-reply>\r\n"
+
"##\r\n";
test(msg);
}
}
Arne