Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python use variable in regex expression

# Short answer:
# The regex expression is a string which can be built up like any string in
# Python

# Example usage:
import re
your_string = 'Your string to search'
variable = 'ring'
re.search('.+' + variable + '.+', your_string) # or:
re.search('.+{}.+'.format(variable), your_string)
Comment

variable in regex python

import re
s = 'I love books'
var_name = 'love'
result = re.search('(.+)'+var_name+'(.+)',s)
print result
var_name = 'hate'
s2 = 'I hate books'
result = re.search('(.+)'+var_name+'(.+)',s2)
print result
Comment

PREVIOUS NEXT
Code Example
Python :: virtual environments for python 
Python :: ram clear in python 
Python :: even numbers in python 
Python :: parallel loops in python 
Python :: django cleanup settings 
Python :: temp python web server 
Python :: floating point python 
Python :: find a key in a dictionary python 
Python :: importing python module from different directory 
Python :: make a label using tkinter in python 
Python :: find word position in string python 
Python :: detailview 
Python :: seaborn distplot 
Python :: ttk button 
Python :: start virtual environment python linux 
Python :: django signals post_save not working 
Python :: python cast to float 
Python :: from one hot encoding to integer python 
Python :: pip install opencv 
Python :: python codes 
Python :: python to c# converter 
Python :: python flask windows 
Python :: test with python 
Python :: how to access http page in pythion 
Python :: python for continue 
Python :: how to make a dice program in python 
Python :: range of y & x in scatter 
Python :: django model remove duplicates 
Python :: sum of array in python 
Python :: enumerate items python 
ADD CONTENT
Topic
Content
Source link
Name
1+1 =