Creating fuzzy matching exceptions with Python's new regex module

前端 未结 1 1440
死守一世寂寞
死守一世寂寞 2021-01-13 16:47

I\'m testing the new python regex module, which allows for fuzzy string matching, and have been impressed with its capabilities so far. However, I\'ve been having trouble ma

1条回答
  •  再見小時候
    2021-01-13 17:06

    Try a negative lookahead instead:

    (?![NEW]|SS)(ST LOUIS){e<=1}
    

    (ST LOUIS){e<=1} matches a string meeting the fuzzy conditions placed on it. You want to prevent it from starting with [NSEW]. A negative lookahead does that for you (?![NSEW]). But your desired string starts with an S already, you only want to exclude the strings starting with an S added to the beginning of your string. Such a string would start with SS, and that's why it's added to the negative lookahead.

    Note that if you allow errors > 1, this probably wouldn't work as desired.

    0 讨论(0)
提交回复
热议问题