Regx + Java : split a text into words and removing punctuation only if they are alone or at the end <p>I am trying to split a string into words but I want to keep, "a.b.c" as a word, and remove the punctuation only if it is alone or at the end of a word e.g. </p> <pre><code>"a.b.c" --&gt; "a.b.c" "a.b." --&gt; "a.b" </code></pre> <p>e.g </p> <pre><code>String str1 = "abc a.b a. . b, , test"; should return "abc","a.b","a","b","test" </code></pre>