title: How to split a sentence into words and punctuations in java
body: <p>I want to split a given sentence of type string into words and I also want punctuation to be added to the list.</p>
  
  <p>For example, if the sentence is: <strong>"Sara's dog 'bit' the neighbor."</strong> 
  <br> I want the output to be: <strong>[Sara's, dog, ', bit, ', the, neighbour, .]</strong></p>
  
  <p>With string.split(" ") I can split the sentence in words by space, but I want the punctuation also to be in the result list.</p>
  
  <pre><code>    String text="Sara's dog 'bit' the neighbor."  
      String list = text.split(" ")
      the printed result is [Sara's, dog,'bit', the, neighbour.]
      I don't know how to combine another regex with the above split method to separate punctuations also.
  </code></pre>
  
  <p>Some of the reference I have already tried but didn't work out </p>
  
  <p>1.<a href="https://stackoverflow.com/questions/7384791/splitting-strings-through-regular-expressions-by-punctuation-and-whitespace-etc">Splitting strings through regular expressions by punctuation and whitespace etc in java</a></p>
  
  <p>2.<a href="https://stackoverflow.com/questions/29255842/how-to-split-sentence-to-words-and-punctuation-using-split-or-matcher">How to split sentence to words and punctuation using split or matcher?</a></p>
  
  <p>Example input and outputs</p>
  
  <pre><code>String input1="Holy cow! screamed Jane."
  
  String[] output1 = [Holy,cow,!,screamed,Jane,.] 
  
  String input2="Select your 'pizza' topping {pepper and tomato} follow me."
  
  String[] output2 = [Select,your,',pizza,',topping,{,pepper,and,tomato,},follow,me,.]
  </code></pre>