Python “regex” module: Fuzziness value

前端 未结 2 1443
温柔的废话
温柔的废话 2021-01-13 23:11

I\'m using the \"fuzzy match\" functionality of the Regex module.

How can I get the \"fuzziness value\" of a \"match\" which indicates how different the pattern is

2条回答
  •  离开以前
    2021-01-14 00:01

    >>> import difflib
    >>> matcher = difflib.SequenceMatcher(None, 'foo', 'for')
    >>> sum(size for start, end, size in matcher.get_matching_blocks())
    2
    >>> max(map(len, ('foo', 'for'))) - _
    1
    >>>
    >>>
    >>> matcher = difflib.SequenceMatcher(None, 'foo', 'food')
    >>> sum(size for start, end, size in matcher.get_matching_blocks())
    3
    >>> max(map(len, ('foo', 'food'))) - _
    1
    

    http://docs.python.org/2/library/difflib.html#difflib.SequenceMatcher.get_matching_blocks http://docs.python.org/2/library/difflib.html#difflib.SequenceMatcher.get_opcodes

提交回复
热议问题