I am a beginner for Python programming. I am exploring Regex. I am trying to Extract a word(Database name) from the Description column. I am not able to give multiple Regex patterns.
please see the description and the code below.
Description
Summary: AD1: Low free DATA space in database AD1ADS: 10.00% Date: 06/28/2017 Severity: Warning Res
Summary: Database SV1V1CH has used log space: 90.00% Date: 02/06/2017 Severity: Warning ResourceId: s
Summary: SAP SolMan Sys=SM1Tempdb,MO=AGEEPM49,Alert=Database Host Status,Desc=A database hos
*** Clearing Event Received *** SNG01AMMSOL04_age SAP SolMan Sys=SM1_SNG01AMMSOL04,MO=AGEEQM46,Alert
Expected Ouput of DB Names Extracted
AD1ADS
SV1V1CH
SM1Tempdb
SNG01AMMSOL04
Code Tried
sentence = df['Description']
frame = pd.DataFrame({'logs': sentence})
import re
pattern = re.compile(r'[dD]atabase (\w+)|Sys=(\w+)')
for _, line in frame.iterrows():
name = pattern.findall(line['logs'])
if name:
line['names'] = name[0]
else:
line['names'] = 'Miscellaneous'
Could anyone please tell me, what mistake I am doing it here.
Output which I am getting Now
(u'AD1ADS', u'')
(u'SV1V1CH', u'')
(u'', u'CM1_CHE01AMMSOL04')
Miscellaneous