title: HIVE string search
body: <p>I am trying to query data (think of it as a column with a long string in a table) in hive. The specific requirement is to filter strings which have a pattern.</p>
  
  <pre><code>example string1: "Some content. AB: xyz-p1 CD: rst-p1"
  
  example string2: "Some content. AB: xyz-p2 CD: rst-p2"
  
  example string3: "Some content. AB: xyz-p1 CD: xyz-p1"
  
  example string4: "Some content. AB: xyz-p2 CD: xyz-p2"
  </code></pre>
  
  <p>(p1 and p2 are patterns, think of them as strings. AB: and CD: are fixed(constant) strings. xyz and rst are also strings and are not constants)</p>
  
  <p>I require that string1 and string2 should be part of the hive query result but not string3 and string4. To be more formal, the strings AB and CD cannot be followed by the same pattern (xyz or rst).</p>
  
  <p>My initial attempt was something like:-</p>
  
  <pre><code>select * from tableName where (col1 like '%AB: %-p1%' or col1 like '%CD: %-p2%') 
  and (col1 not like '%AB: %-p1%') and (col2 not like '%CD: %-p2%')
  </code></pre>
  
  <p>However this does not seem to give the expected result.</p>