[Tutor] Clarification on using regular expression
Arulanand Nagarajan (RBEI/EEV51-EC)
Nagarajan.Arulanand at in.bosch.com
Fri Aug 30 06:24:17 EDT 2019
Hi,
I am currently working on a python script which uses regular expressions for processing some data.
I have some string as below(each in new line):
aa1 !=5
bb1 >=1
cc1 ==1
dd2 <= 2
e3 <2
>From this string, I want to get a list of all the labels that are before the comparison operator and another list that contains the values after the comparison operator.
That is
list1 = ['aa1','bb1','cc1','dd2','e3']
list2 = ['5','1','1','2','2']
How will I be able to do that?
I was able to get label before the '==' operator using the command below:
[v.strip() for v in re.findall("[a-zA-Z0-9_.]* ? (?==\=)", string)].
But i want all the labels that are placed before all the comparison operators (!=, ==, <, >, <=, >=). i have tried the commands below:
[v.strip() for v in re.findall("[a-zA-Z0-9_.]* ? (?(!=|==|<=|>=|>|<)\=)", string)]
[v.strip() for v in re.findall("[a-zA-Z0-9_.]* ? (?(!=|==|<=|>=|>|<))", string)]
Can you pl. help me on this?
Best regards,
Nagarajan Arulanand
RBEI/EEV5-EC
More information about the Tutor
mailing list