This question answers how we can split a string using multiple delimiters? Is it also possible to split a String using multiple keywords.
For example:
String myString = (One Two Three) AND (Four Five Six) OR (Six Seven Eight)
And I want to split myString at both AND and OR so that I get:
someArray[0] = (One Two Three)
someArray[1] = (Four Five Six)
someArray[2] = (Six Seven Eight)
I do not know much of regex, so any help or advice would be helpful. Thanks in advance.
Try this :
String[] someArray=yourString.split("(AND)|(OR)");
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