I’m trying to detect logical connectors in a string (AND, OR, NOT) using Java. What I would like to do is:
- Given a string (e.g ((blue) AND (yellow) OR (pink)), separate each word and put them in a List. The result should be something like {“blue”,”yellow”,”pink”}
I know that for match the words, I need to use a regex like \b(AND|OR|NOT)\b.
But I don’t know how return each word after or before the connector.
Other question: Is usefull use regex or maybe I have to use contains()?
How about this?
Output: