Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8374999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:03:57+00:00 2026-06-09T15:03:57+00:00

I need a sentence parser. Where parser splits complete sentence based on white character.

  • 0

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.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T15:03:59+00:00Added an answer on June 9, 2026 at 3:03 pm

    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:

         String s = "This is the work (my real job) which is great, and (also some stuff";
    
         ArrayList<String> words = new ArrayList<String>();
         Scanner sentence = new Scanner(s);
         boolean inParen = false;
         StringBuilder inParenWord = new StringBuilder();
         while(sentence.hasNext()) {
            String word = sentence.next();
            if(inParen) {
               inParenWord.append(" ");
               inParenWord.append(word);
    
               if(word.endsWith(")")) {
                  words.add(inParenWord.toString());
                  inParenWord = new StringBuilder();
                  inParen = false;
               }
            }
            else {
               if(word.startsWith("(")) {
                  inParen = true;
                  inParenWord.append(word);
               }
               else {
                  words.add(word);
               }
            }
         }
    
         if(inParenWord.length()>0) {
            words.add(inParenWord.toString());
         }
    
    
         for(String word : words) {
            System.out.println(word);
         }
    

    which would output:

    This
    is
    the
    work
    (my real job)
    which
    is
    great,
    and
    (also some stuff
    

    Or using a Pattern/Matcher:

         String s = "This is the work (my real job) which is great, and (also somet stuff";
    
         ArrayList<String> words = new ArrayList<String>();
    
         Pattern p = Pattern.compile(" ?([^(][^ ]+|\\([^\\)]+\\)?)");
         Matcher m = p.matcher(s);
    
         while(m.find()) {
            words.add(s.substring(m.start(),m.end()).trim());
         }
    
         for(String word : words) {
            System.out.println(word);
         }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to extract the word following 'NN' in this particular sentence? (ROOT (SBARQ
I need to center a particular word in a sentence by truncating the beginning
Hello I need to replace only single occurrence of substring Example: Some sentence #x;#x;#x
Need to match the first part of a sentence, up to a given word.
I need to take a sentence in that is all on one line with
For example, if I need to add a sentence to the end of a
I'm using MySQL 5, and I need to do this sentence to get the
I need a regular expression to parse words from a sentence or a paragraph.
I need to calculate word frequencies of a given set of adjectives in a
I have a longer sentence >200 characters. I need to show on the screen

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.