I need a sentence parser. Where parser splits complete sentence based on white character. And it treats complete contents inside parenthesis as a single word (parsed one).
Input sentence:-
“This is the work (my real job) which is great.”
Output required:-
This
is
the
work
(my real job)
which
is
great.
Not sure if there’s a nice way to use this regexp to parse out words from a sentence like that. You may need to iterate through the sentence regardless. I don’t think
String.split()is going to do it for you. Just write a loop to do this for you, then you can handle the specifics of when the parens don’t match. For example, this will assume everything is a word even if the sentence ends and there is no closing parentheses:which would output:
Or using a Pattern/Matcher: