I am in need to use the Word Boundary(\y) as a condition to match the exact word which is been searched as a Query Param. I am writing this regex and executing in PostgreSQL but it is returning FALSE. text_search_value = "apple." (Which needs to be exactly matched in the {doc_table} which is presented in the code) My code vector_split_text = re.sub("\.|\-|/", " ", text_search_value) text_search_value = re.escape((re.sub("\)",")",re.sub("\(","(",text_search_value)))) converted_part_query = f""""{doc_table}".lni IN (SELECT BTRIM(xxx) FROM "{docsplit_table}" WHERE yyy IN ({all_rcis}) AND doc_text_vector @@ phraseto_tsquery('simple', '{vector_split_text}'))""" converted_part_query = ( "(" + converted_part_query + f""" and "{doc_table}".document::text ~ '\y{text_search_value}\y'""" + ")" ) PostgreSQL Query select 'apple.' ~ '\yapple\.\y' Expected Result The Select Query should return TRUE while executing in the PostgreSQL Table with the help of regex fixed. Continue reading...