PY
py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# regexp library
import re
#This are q.getresults output
rows = [
{'mail': 'charan123@mysore.com', 'distinguishedName': 'OU=Mysoreusers,DC=mysore,DC=com'},
{'mail': 'kiran123@mysore.com', 'distinguishedName': 'OU=Mysoreusers,DC=mysore,DC=com'}
]
Emaillist=[]
Namelist=[]
for row in rows:
# the get() method will return None if the key does not exist
if row.get("mail"):
# regexp matching any character until the first @ in the 'mail' value
Emaillist += [re.match("[^@]+", row["mail"]).group(0)]
if row.get("distinguishedName"):
# regexp matching any character between CN= and the first comma
Namelist += [re.match("CN=([^,]+)", row["distinguishedName"]).group(1)]
print(Emaillist)
print(Namelist)
#need output as below
#output in first list [charan123,kiran123]
#output in second list [charan M, Kiran]
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run