I am trying to search for a substring with the specify pattern using re library. I wrote a function to do that but end up getting this error: Type Error: cannot concatenate str and integers. Below is my function;
def searchValue(obs, concept):
try:
found = re.search('## !!'concept+'=(.+?)!! ##',obs)
except AttributeError:
found = 'null'
return found
obs= '!!1834=7850!! ## !!1915=Patient is awaiting imaging results, then start darcabazine 250 ml every 21 days.!! ## !!1915=Patient is HIV positive since 2016,no presents with pains on the plantar surface and pelvic pain.!! ## !!5096=2013-07-29!! ## !!5219=1068!! ## !!6504=7189!! ## !!6509=6511!! ## !!6575=1107!! ## !!6605=1065!! ## !!7191=MELANOMA OF THE RIGHT HEEL.!! ## !!8723=5622!!'
bett = searchValue(obs, 1915)
print(bett)
Any help will be appreciated.
'## !!'+concept+'=(.+?)!! ##'. Python is trying to concat"str1""str2"<-- valid python syntax. But in your case"str2"is anintwhich is why it errored.