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"

0

1 Answer 1

1

You can escape the currently brackets by adding another currently brackets

x = regex.search(rf"(?b){variable}{{d}}",s)
Sign up to request clarification or add additional context in comments.

1 Comment

@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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.