评估一个字符串是否“几乎”匹配另一个

时间:2021-05-14 21:40:23

标签: sql regex postgresql

在 psql 中有没有办法找出一个字符串是否与另一个字符串几乎相同?

例如:“This sting, on screen”几乎匹配“This String, on screen”

1 个答案:

答案 0 :(得分:1)

您可以使用levenshtein函数

CREATE EXTENSION fuzzystrmatch;

select levenshtein('This sting, on screen'::text, 'This String, on scren'::text); 
-- returns 3
select levenshtein('A very diferent texto'::text, 'of other kind of words'::text); 
-- returns 18

https://www.postgresql.org/docs/13/fuzzystrmatch.html

相关问题