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)");
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments