I am trying to split a string into several lines, but instead of using the string with only one simple regular expression pattern, I am trying to use a regular expression pattern that will split the string into different lines if it detects certain characters, but the characters are different. Instead of breaking a line into different lines, it gives me every single character in the specified line.
String[] splitstr = line.split("([&]{2})?([|]{2})?(!=)?");
Using the line above, I have a variable called line , which, for example, puts this line from a file:
:if[input=right || input=Right]:
I'm just wondering if there is a way to make this separation into
":if[input=right", "input=Right]:"
And if I enclose the line as follows:
:if[input=right || input=Right && input != null]:
So that it breaks into
":if[input=right", "input=Right", "input != null]:"
I used String#split(regex) for the character || , and it worked fine, but now that I want it to crash wherever there is || or && or != , and I want my code to be efficient and clean and easy to read.
source share