Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #variable #regex #expression
ADD COMMENT
Topic
Name
4+3 =