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 :: specify the number of decimals in a dataframe 
Python :: tkmessagebox not found 
Python :: python continue 
Python :: python render_template 
Python :: webbrowser python 
Python :: pandas replace substring in column names 
Python :: python Non-UTF-8 code starting with 
Python :: how to make a minute counter in python 
Python :: pandas column by index 
Python :: python remove empty list 
Python :: Palindrome Check using for loop in python 
Python :: compile python to pyc 
Python :: convert pandas dataframe/ table to python dictionary 
Python :: pandas series quantile 
Python :: anova test in python 
Python :: python snakes 
Python :: python regex match words 
Python :: filter function in pandas stack overflow 
Python :: how to add an item to a list in python 
Python :: python get pixel color from screen 
Python :: where are python libraries installed in windows 
Python :: python socket check if still connected 
Python :: pandas duplicated rows count 
Python :: python sort two key 
Python :: Read text file line by line using the readline() function 
Python :: To View the entire Row and Column in a Dataframe 
Python :: template string python 
Python :: .encode python 
Python :: pandas backfill 
Python :: run multiple function with multiprocessing python 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =