Bod has asked for the wisdom of the Perl Monks concerning the following question:
As I mentioned in Yet another Encoding issue..., I am writing an AI chatbot based around AI::Chat that holds a conversation in Turkish and corrects any mistakes in the Turkish supplied by the user. Of course, there are not always mistakes so a correction is not always needed.
I've promoted the AI that
"if there are no mistakes that need correcting reply with the single word "Perfect" and do not add any other words to your reply."
But being AI, it can be unpredictable! Sometimes, it will quote the Turkish and then write "Perfect" on a separate line.
Currently I check for whether there is a correction like this:
if ($reply !~ /^perfect/i) { $chatReply->{'correction'} = $reply; }
I don't want to check for "Perfect" anywhere in the reply as it might form part of a valid correction. So I am thinking of checking that "Perfect" appears either at the start of the reply or at the end like this:
if ($reply !~ /^perfect/i and $reply !~ /perfect$/i) { $chatReply->{'correction'} = $reply; }
But is there a way of combining those two regexps into just one? It seems there should be...
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Regexp match start or end
by hippo (Archbishop) on Jun 02, 2024 at 18:09 UTC | |
by stevieb (Canon) on Jun 04, 2024 at 08:30 UTC | |
Re: Regexp match start or end
by syphilis (Archbishop) on Jun 02, 2024 at 13:40 UTC | |
Re: Regexp match start or end
by LanX (Saint) on Jun 02, 2024 at 13:39 UTC | |
Re: Regexp match start or end
by Boldra (Deacon) on Jun 05, 2024 at 14:02 UTC | |
Re: Regexp match start or end
by harangzsolt33 (Chaplain) on Jun 04, 2024 at 04:13 UTC |