Java.util.regex.patternsyntaxexception
I have modified the BluetoothChat code to receive serial data from a micro-controller to my android phone. When I run the following code snippet it gives java.util.regex.PatternSy
Solution 1:
matches()
uses regular expressions (regex) for matching the input and *
is a regex metacharacter, meaning zero or more of the previous token. Since there's no previous token, it's a syntax error.
If you want to match *
literally, escape it with backslash:
readMessage.matches("\\*")
or use some of the string-matching functions such as equals()
that don't use a regular expression.
Solution 2:
Here is your problem :
if(readMessage.matches("*")
If you want to match everything, then use ".*
.
Also, like laalto says in his answer. If you want to match everything, you have to escape *
either by using Pattern.quote()
or by simply using two slashes "\\*"
.
Post a Comment for "Java.util.regex.patternsyntaxexception"