I am attempting to use java scanner with the following set of delimiters & = ~ ^ (ampersand, equals, tilde, caret) by using method useDelimiter("&|=|~|^");.
All the delimiters work OK apart from ^ which is ignored: why is that?
I cannot see why in the Scanner documentation.
You need to escape
^, like this:useDelimiter("&|=|~|\\^"). That’s because^is a meta-character in regular expressions, and theStringparameter ofuseDelimiter()ends up being compiled to a regexPattern.Equivalently, you could write the delimiter like this, in this case there’s no need to escape the
^:useDelimiter("[&=~^]")