Check sentence is matched with a template

I need to check the given sentence is matched with existing templates.

User input:
Dear Ram, hello this is the 8th message with some cookies. This will make the sentence8th.
Predefined Template:
Dear {#var#}, hello this is the {#var#} message with some {#var#}. This will make the sentence{#var#}.

This will return TRUE.

Note: Predefined templates may/may not have spaces.

Are you familiar with regular expressions? If so then is there a reason you cannot use them? If so then it will save time if you can explain why.

I am not familiar with pregs. I figured myself with mysql query
$sql = "SELECT template_id FROM templates WHERE ‘$userinput’ LIKE REPLACE( REPLACE(template_text, ‘{#var#}’, ‘%’),’/’, ‘’) ";

Just wondering is there any other way to fasten the process?

I do not know what pregs are. And if you must use SQL then it would have helped to say so in the original question.

Perl-compatable REGular expressions. (don’t ask where the E in expressions went.)
The family of functions that php uses for regex matching. preg_match, preg_split, etc.

So cuteprabakar1 knows what regular expressions are enough to know to call them pregs.