0

I am trying to match a target word in a text string, allowing for fuzziness

import regex
text = 'hello this is a test'
pattern = '(test){e<=2}'

however, regex.search(pattern, text, regex.IGNORECASE) returns 'a test', how can I made it match only the exact pattern (when possible) and not start matching earlier using the allowed fuzziness ?

Asddfg
  • 237
  • 3
  • 13
  • 1
    You need to use `(test){e<=2}` to apply the quantifier to the whole word and use `regex.ENHANCEMATCH`. With `test{e<=2}`, the quantifier is only applied to `t` – Wiktor Stribiżew Feb 19 '20 at 21:00
  • Sorry, I did include the parenthesis on my hand but forgot to add them here – Asddfg Feb 19 '20 at 21:02
  • 1
    Ok, the answer is at https://stackoverflow.com/questions/43048183/python-regexs-fuzzy-search-doesnt-return-all-matches-when-using-the-or-operato/43048502#43048502 `regex.ENHANCEMATCH` is already yielding the expected result, as is `regex.BESTMATCH`. [Online demo](https://rextester.com/CMYVC78512). – Wiktor Stribiżew Feb 19 '20 at 21:11

0 Answers0