What I have looked at already: how to use a variable inside a regular expression
Here is the code I have:
import re
#take user input as an argument
print('Enter 1st Argument: value to strip.')
user_input = input()
#take value to strip off as another argument
print('Enter 2nd Argument: The value to strip off the 1st value.')
strip_value = input()
#Recreate Strip Function
def regex_strip(value,what_to_strip):
thing2 = 'L'
what_to_strip = re.compile(r + re.escape(thing2))
print(what_to_strip)
#fv = what_to_strip.search('tigers named L')
#print(fv.group())
regex_strip(user_input, strip_value)
I am expecting the user to submit two values. The first value is the value that will be subject to the stripping. The 2nd value is what is being stripped.
In my function, I am hard-coding values in order to test my regular expression.
Error message I am getting:
name 'r' is not defined
what am I doing wrong?
Edit #1: This is what I have tried:
thing2 = '\d'
what_to_strip = re.compile(re.escape(thing2))
print(what_to_strip)
fv = what_to_strip.search('123')
print(fv.group())
Result:
'NoneType' object has no attribute 'group'
My thoughts: Something is wrong with thing2 = '\d'
I want just '\d'
but I am getting '\\\\d'
hmm.