Help is needed.
line.split("*");
I used this line of code to split a string into an asterisk mark. However, I got an error from my compiler. It says, "INVALID REGULAR EXPRESSION: DANGLING META CHARACTER '*'"
How to resolve this problem? Thanks in advance.
To split a string by a regular expression, pass a regex as a parameter to the split() method, e.g. str. split(/[,. \s]/) . The split method takes a string or regular expression and splits the string based on the provided separator, into an array of substrings.
Backslashes in Java. The backslash \ is an escape character in Java Strings. That means backslash has a predefined meaning in Java. You have to use double backslash \\ to define a single backslash. If you want to define \w , then you must be using \\w in your regex.
split(String regex) method splits this string around matches of the given regular expression. This method works in the same way as invoking the method i.e split(String regex, int limit) with the given expression and a limit argument of zero. Therefore, trailing empty strings are not included in the resulting array.
*
has special meaning in regular expressions. You have to escape it.
line.split("\\*");
Try this statement:
line.split("\\*");
It is because you used a "*", that is a regular expression. If you want to use this caracter, you need tu put something like that:
line.split("\\*");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With