0

I'm using the regex library in python and trying to do fuzzy matching.

I need to use a variable in my search string and this is the code I got following this post

x = regex.search(rf"(?b){variable}{d}",s)

which gives NameError: name 'd' is not defined

The issue is that I want to specify the type of error with the {d} tag but that is also interpreted as a variable. The only solution I have come up with so far is just to assign d = "d". Looking for a more "proper" way to accomplish this.

Example case:

variable = "amazing"
s = 'amaing analogy'
x = regex.search(rf"{variable}{d}",s)
x.group()

intended output : "amaing"

zhao
  • 91
  • 6

1 Answers1

1

You can escape the currently brackets by adding another currently brackets

x = regex.search(rf"(?b){variable}{{d}}",s)
Leo Arad
  • 4,452
  • 2
  • 6
  • 17
  • @zhao @leo what is this `d` syntax? I can't find any good documentation or examples on how to use error tag `{e<=1}` or `{e<=.97}` type examples. – data_steve Aug 21 '20 at 14:51