+ 2
Python regex match question
Input exactly as below:: List of devices attached emulator-5554 device Need to perform regex match to get the value before (\tdevice) that is emulator-5554 I was trying below code: m = re.findall(r'(\tdevice)',a)[0] if m: print m else: print "none"
3 Antworten
+ 6
That will work too, but the search will never return None this way. It will always return a value, even if it's blank.
+ 5
Check it out, just input: device
https://code.sololearn.com/c53M1pnKpmvY/?ref=app
Try out your regexes at:
www.regex101.com
+ 1
m = re.findall("(.+)\tdevice",a)
if m:
print m
else:
print "none"