How to match a sentence exactly, rather than substring match
<p>So I created a simple reddit bot using PRAW:</p>

<pre><code>import praw
import time
from praw.helpers import comment_stream

r = praw.Reddit("han_solo_response")
r.login()

target_text = "I love you"
response_text = "I know"

processed = []
while True:
    for c in comment_stream(r, 'all'):
        if target_text in c.body and c.id not in processed: 
        #if find comment not in cache
        c.reply(response_text)
        processed.append(c.id)   #then push the response 
        time.sleep(20)
</code></pre>

<p>It generates the han solo response " i know" every time someone anywhere on reddit posts " i love you" per the famous star wars movie exchange. It is working now but it is catching anything containing "i love you" eg i had to delete one comment where the guy was saying " i love your car".</p>

<p>How can I limit its trigger to precisely "I love you", not "your" or any other word containing "you", or for that matter, make it so that the response is only triggered by the standalone phrase, not when it appears within the context of a sentence.</p>

<p>This line:</p>

<p><code>if target_text in c.body and c.id not in processed:</code></p>

<p>should be:</p>

<p><code>if target_text == c.body and c.id not in processed:</code></p>

<p>If you want to make it case-insensitive:</p>

<p><code>target_text = "i love you"</code></p>

<p>and</p>

<p><code>if target_text == c.body.lower() and c.id not in processed:</code></p>

python bots reddit