M
Martin Gregorie
Quick question: in a regex with alternative matching strings, is it safe
to assume that the alternatives will always be tested in the order given?
For example, I have a String, s where s = "xxx\rxxxx\nxxxx\r\nxxxx\r\n";
is it safe to assume that String r = s.replaceAll("\r\n|\r|\n", "\r\n");
will always yield r = "xxx\r\nxxxx\r\nxxxx\r\nxxxx\r\n" for all strings
containing \r, \n or \r\n ?
Its doing that with the (limited) test set I've run it on so far, but I'd
like to know that isn't a fluke. In case you're wondering, I need a
quarantee that, no matter what programs have handled a file on a variety
of operating systems, after applying replaceAll() the line terminators
will always by CRLF because this affects a hash check on the whole file.
to assume that the alternatives will always be tested in the order given?
For example, I have a String, s where s = "xxx\rxxxx\nxxxx\r\nxxxx\r\n";
is it safe to assume that String r = s.replaceAll("\r\n|\r|\n", "\r\n");
will always yield r = "xxx\r\nxxxx\r\nxxxx\r\nxxxx\r\n" for all strings
containing \r, \n or \r\n ?
Its doing that with the (limited) test set I've run it on so far, but I'd
like to know that isn't a fluke. In case you're wondering, I need a
quarantee that, no matter what programs have handled a file on a variety
of operating systems, after applying replaceAll() the line terminators
will always by CRLF because this affects a hash check on the whole file.