Having list of strings as below:
['Communcation between: ACC_Verkehrssinn and SG_ACC_22\nUsing testing method: MinMaxMid',
'Communcation between: ACC_Status_Laengs and SG_ACC_22\nUsing testing method: MinMaxMid',
'Signal Name:WLA_FC1_Obj10angleLeft\nCommuncation between: SG_WLA_FC1_Obj01_30 and
SG_WLA_FC1_Obj01_30\nUsing testing method: MinMaxMid',
'Signal Name:WLA_FC1_Obj10angleRight\nCommuncation between: SG_WLA_FC1_Obj01_30 and
SG_WLA_FC1_Obj01_30\nUsing testing method: MinMaxMid']
Want to read list elements which contains ‘Signal Name:’ and capture its value. Here in this case output should be:
WLA_FC1_Obj10angleLeft
WLA_FC1_Obj10angleRight
Any help is appreciated.
>Solution :
We can use a list comprehension here:
inp = ['Communcation between: ACC_Verkehrssinn and SG_ACC_22\nUsing testing method: MinMaxMid', 'Communcation between: ACC_Status_Laengs and SG_ACC_22\nUsing testing method: MinMaxMid', 'Signal Name:WLA_FC1_Obj10angleLeft\nCommuncation between: SG_WLA_FC1_Obj01_30 and SG_WLA_FC1_Obj01_30\nUsing testing method: MinMaxMid', 'Signal Name:WLA_FC1_Obj10angleRight\nCommuncation between: SG_WLA_FC1_Obj01_30 and SG_WLA_FC1_Obj01_30\nUsing testing method: MinMaxMid']
output = [re.search(r'Signal Name:\s*(\S+)', x).group(1) for x in inp if 'Signal Name:' in x]
print(output)
This prints:
['WLA_FC1_Obj10angleLeft', 'WLA_FC1_Obj10angleRight']