*** a/contrib/pg_trgm/trgm_op.c
--- b/contrib/pg_trgm/trgm_op.c
***************
*** 284,293 **** get_wildcard_part(const char *str, int lenstr,
  	{
  		if (in_escape)
  		{
- 			in_escape = false;
- 			in_wildcard_meta = false;
  			if (iswordchr(beginword))
  				break;
  		}
  		else
  		{
--- 284,292 ----
  	{
  		if (in_escape)
  		{
  			if (iswordchr(beginword))
  				break;
+ 			in_escape = false;
  		}
  		else
  		{
***************
*** 334,340 **** get_wildcard_part(const char *str, int lenstr,
  	 */
  	endword = beginword;
  	in_wildcard_meta = false;
- 	in_escape = false;
  	while (endword - str < lenstr)
  	{
  		clen = pg_mblen(endword);
--- 333,338 ----
