title: Teradata REGEXP_SIMILAR matching exact string
body: <p>I have list of databases and tables obtained like this:</p>
  
  <pre><code>SELECT TRIM(DatabaseName) || '.' || TRIM(TableName) AS DatabaseTable
  FROM DBC.TablesV t1
  WHERE TableKind IN ('T','O','V')
  </code></pre>
  
  <p>I now want to match them to dbc.TablesV.RequestText to build a hierarchy of my database views.
  At first i did it with simple join like below</p>
  
  <pre><code>JOIN DBC.TablesV t2
  ON t2.RequestText LIKE '%' || DatabaseTable || '%'
  </code></pre>
  
  <p>but unfortunately, we have tables like T1010_User and T1010_User_Hist, and databases like <code>DB_STAGE</code> and <code>Q_DB_STAGE</code> so i decided to add spaces to % to a LIKE clause making it <code>LIKE '% ' || DatabaseTable || ' %'</code> but then it fails to get proper results because sometimes tablename is at the end of a requesttext like this: <code>(...) DB_STAGE.TableName;</code> and sometimes its like this:</p>
  
  <pre><code>(...)
  FROM
  DB_STAGE.TableName t1
  (...)
  </code></pre>
  
  <p>I decided to use REGEXP_SIMILAR to match them with <code>WHEN REGEXP_SIMILAR() = 1</code> but my regex-fu is weak, so I cannot build regex that will do something like:</p>
  
  <pre><code>((anything other than a letter/number) or nothing) DatabaseTable ((anything other than a letter/number) or nothing)
  </code></pre>
  
  <p>This is to build hierarchy of views to help with migrating data to a different database.</p>
  
  <p>This is very simplified case:</p>
  
  <pre><code>CREATE VOLATILE TABLE test1
  (
  c0 SMALLINT,
  c1 varchar(100)
  )ON COMMIT PRESERVE ROWS;
  
  INSERT INTO test1 VALUES(1,'aaa
  Q_abcdef.abcdef');
  INSERT INTO test1 VALUES(2,' Q_abcdef.abcdef ');
  INSERT INTO test1 VALUES(3,'aaa
  DQ_abcdef.abcdef ');
  INSERT INTO test1 VALUES(4,' S_abcdef.abcdef');
  INSERT INTO test1 VALUES(5,'Q_abcdef.abcdefg');
  INSERT INTO test1 VALUES(6,' sdfs
  Q_abcdef.abcdefg');
  INSERT INTO test1 VALUES(DQ_abcdef,'    7.abcdefg');
  INSERT INTO test1 VALUES(8,' S_abcdef.abcdefg');
  INSERT INTO test1 VALUES(9,'Q_abcdef.abcdef;');
  INSERT INTO test1 VALUES(10,' Q_abcdef.abcdef;');
  INSERT INTO test1 VALUES(11,'DQ_abcdef.abcdef;');
  INSERT INTO test1 VALUES(12,' S_abcdef.abcdef;');
  </code></pre>
  
  <p>I need to match 1, 2, 9 and 10. The ones that have string Q_abcdef.abcdef exactly.</p>