title: Java: How to utilize advanced string replaceAll Regex w/ and w/out Lookahead/Lookbehind
body: <p>I am attempting to only accept regular words with or without a hyphen in the middle of the word or an apostrophe in either the middle or at the end of the word. So any numeric string or one with any other special characters would be replaced with white-space. Also preceding white-space would not need to be accounted for as these strings would be read in from a file and already separated using white-space.</p>
  
  <p>I.e. "0", "-hi", "hi-", and "'hello" would all be rejected. </p>
  
  <p>However, "apple", "Ben's", "Ben'", and "well-respected" would be accepted. </p>
  
  <p>I am trying to figure this out with Java's String replaceAll functionality. I'd like to know how to do this with a "simple" regular expression and also how to utilize a more advanced lookbehind/lookahead to achieve this.</p>
  
  <p>So far, in regard to the RegEx, this is what I have attempted:</p>
  
  <pre><code>String tempString;
  tempString = tempString.replaceAll("^([a-zA-Z]+(-)?[a-zA-Z]+)"," ");
  tempString = tempString.replaceAll("^([a-zA-Z]+(')?[a-zA-Z]*)"," ");
  //Basically if it does not meet this condition, replace w/ whitespace
  </code></pre>
  
  <p>As of right now, the syntax of the regular expressions are not even correct. Testing either of these two against the associated "non-accepted" words above will not replace them with " ". On top of this, I need to combine these two RegEx's into one to allow for proper overall functionality.</p>
  
  <p>On a  similar note, and as I understand, I can utilize a lookahead/lookbehind to achieve the desired result. However, after reading up on the process, I am confused as to the syntax that would be inserted into the replaceAll function.</p>
  
  <p>So, my two questions are as follows:</p>
  
  <ol>
  <li>What can I change in the RegEx's syntax to check for both hyphens and apostrophes in one replaceAll function call?</li>
  <li>How can I utilize a lookahead/lookbehind to achieve the same goal?</li>
  </ol>
  
  <p>Please note I am NOT looking for other solutions as I am trying to better understand RegEx's. Also this is my first question on here so apologies for any formatting issues or other dumb things.</p>
  
  <p>Thanks!</p>