title: Regular expression to remove last word in a string
body: <p>I have a string like this: &quot;87 CAMBRIDGE PARK DR&quot;. I have used the below regular expression to remove the last word &quot;DR&quot;, but it also removes the word &quot;PARK&quot;...</p>
  <p>Below is my code...</p>
  <pre><code>String regex = &quot;[ ](?:dr|vi|tes)\\b\\.?&quot;; /* Regular expression format */
  
  String inputString =&quot;87 CAMBRIDGE PARK DR&quot;; /* Input string */
  
  Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
  Matcher matcher = pattern.matcher(inputString);
  inputString = matcher.replaceAll(&quot;&quot;);
  </code></pre>
  <p>Now the output is &quot;87 CAMBRIDGE&quot;..</p>
  <p>But I need the output as &quot;87 CAMBRIDGE PARK&quot;.</p>