-3

EDIT: So apparently, this is a string interpolation in regex. Thanks for clarifying.

I have a input function that is named omj.

omj 

When I run it, it gives me

"obik"

I then use that output in this regex function

re.findall("\w*obik\w*",dataframe)

I received EXACTLY what I wanted, which is the answer

"Yaobikuni"

Notice that "obik" is in the word, and there is only one match for it. Is there a way to put the input omj in the regex function to get Yaobikuni straightforwardly, or is this the only way it would work?

EDIT: I don't understand why people are downvoting, but I thought I made it clear that omj can be considered as an input string that gives the answer obik.

omj = """obik"""

EDIT2: Thank you for the help @Nick Chapman . I tried this on the first time and I thought it might not have been possible to infuse the input omj on an regex function:

re.findall("\w*"omj"\w*",dataframe)
8
  • 1
    This is very confusing. Can you clarify your input/output/question? What is omj: Is it's a function or an input? Commented Dec 7, 2017 at 15:47
  • @ctwheels: It's an input, and I get obik as an output when running it. Commented Dec 7, 2017 at 15:50
  • So if it's an input and you get an output of obik from it it's a function? How does omj === obik? Commented Dec 7, 2017 at 15:51
  • @ctwheels: it's a function that gives obik that I equate it to omj. Therefore, you may conclude that omj = """obik""" Commented Dec 7, 2017 at 15:56
  • So one could say that omj is a function similar to def omj(): print("obik")? Commented Dec 7, 2017 at 16:00

2 Answers 2

1

The first argument is just a string, so your real question is how to do string interpolation in Python.

How about this:

re.findall("\w*{}\w*".format(omj()), dataframe)
Sign up to request clarification or add additional context in comments.

1 Comment

I believe I clarified it again in my first edit, but thank you. This works for functions.
0

Can't you just do

re.findall("\w*" + omj + "\w*",dataframe)

2 Comments

Without a pair of parenthesis after omj() this would fail fail with TypeError: must be str, not function
I don't believe that omj is a function in this case, just a string.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.