<?xml version="1.0" encoding="windows-1252"?>
<node id="1005725" title="DBD-SQLite Regexp" created="2012-11-26 12:41:27" updated="2012-11-26 12:41:27">
<type id="115">
perlquestion</type>
<author id="872655">
welle</author>
<data>
<field name="doctext">
&lt;p&gt;Hello&lt;/p&gt;
&lt;p&gt;I am trying to extract from a column of a SQLITE-DB (containing text sentences) sentences that contain a string ($query). I normally use:&lt;/p&gt;
&lt;code&gt;
$results  = $dbh-&gt;selectall_arrayref("SELECT ID, sentence  FROM texts WHERE sentence LIKE '%$query%'"
&lt;/code&gt;
&lt;p&gt;which is working pretty good (every sentence containing $query somewhere is extracted). What I'd like to implement is a matching only for entire words. I thought the following would do the game (note the white spaces between and after $query):&lt;/p&gt;
&lt;code&gt;
$results  = $dbh-&gt;selectall_arrayref("SELECT ID, sentence  FROM texts WHERE sentence LIKE ' %$query% '"
&lt;\code&gt;
&lt;p&gt;
Of course it doesn't work as I expected:
&lt;code&gt;
$query="tag"
sentence1= "Put tags around your paragraphs"
sentence2= "Put a tag around your paragraphs"
sentence3= "I am tagging your paragraphs"
sentence4= "There are many advantages"
&lt;/code&gt;
&lt;p&gt; I get rid only of sentence4 (no white spaces left and right of "tag"&lt;/p&gt;
&lt;p&gt;What I am doing wrong?"&lt;/p&gt;
</field>
</data>
</node>
