In my current project I am confronted with the problem of having a string that can be constructed in 2 patterns. It consists of only one natural number, or 2 natural numbers with a '-' in between. I need to be able to distinguish between them. I would like to use the following code for this:
if (STRING.matches("*-*"))
{
//Do something
} else {
//Do something else
}
However, it gives me the following error:
Exception in thread "Thread-2" java.util.regex.PatternSyntaxException: Dangling meta character '*' near index 0
I also tried to put '#' at the beginning of the string ( of course I added it to the pattern), but this only caused the else part of the if-query to be executed.
Hope you can help me
isi_ko
java.util.regex.Pattern? It explains java's regex syntax.