title: Match if something is before or after certain word
body: <p>I am trying to build a pattern to match all counties from a sentence
  eg. 
  "ABCD XYZ County Herefordshire or Co.Kent or London County"</p>
  
  <pre><code>((co(unty)?\s)|(co\.\s?))?(?P&lt;county&gt;[a-z]{4,})(\scounty)?
  </code></pre>
  
  <p>But above pattern will also return "ABCD" as both expressions around "county" are optional.</p>
  
  <p>Do I have to use two separate regular expressions or is there any way around it?</p>
  
  <p><strong>EDIT</strong>
  What I am trying to do is get all the counties from a sentence. I consider word a county name if it is followed by "county" or preceded either of "co.", "co ", "county ". Multiple expressions like that divided by " or " are allowed. Once matched next step would be to remove whole expression eg "Co.London" from original string.</p>
  
  <p><strong>EDIT 2</strong><br>
  OK sorry for confusion I know my questions isn't clear. What I am trying to do is:<br>
  1. User enters something like 'ABCD County XYZ or Co.London or Kent County or county Herefordshire'<br>
  2. I want to get anything that is any of: "co.word" or "co word" or "county word" or "word county"  So ideally I should get this: 'ABCD County,County XYZ,Co.London,Kent County,county Herefordshire'<br>
  3. I remove 'county' or 'co' etc from matched expression and check each against list of counties I have. If word is a county name I want to remove the whole expression from the original query. </p>