Your code is almost there except for extracting matched string, you need to access it using .group() for full match. Following is your modified code,
import re
presplit = "CN=CTX_APP_Bytemobile_UPM,OU=EEGroups,OU=EEOU,DC=ssa,DC=oam,DC=uk,DC=tmo"
x = re.search("(?<=^CN=)\w+(?:\s+\w+)*", presplit)
if(x):
print(x.group())
Which prints following like you expected,
CTX_APP_Bytemobile_UPM
Also, for capturing spaces as well, you need to use this regex,
(?<=^CN=)\w+(?:\s+\w+)*
^^^^^^^^^^^ This additional part enables it to optionally capture space followed by some word characters
If you notice, I have placed a ^ before CN= in positive look behind so it doesn't match other CN= in middle of the string and just CN in start of line.
Check this demo as well
Besides your positive look behind regex, you can use another simple regex, which is almost 20 times faster then look behind one but uses capture group. This ([^,]+) part in following regex captures the name you are interest in.
^[^=]*=([^,]+)
This one is 20 times faster than earlier one
Check out this Python code,
import re
arr=['CN=CTX_APP_Bytemobile_UPM,OU=EEGroups,OU=EEOU,DC=ssa,DC=oam,DC=uk,DC=tmo = CTX_APP_Bytemobile_UPM','CN=OSGRP_IP_Transport,OU=EEGroups,OU=EEOU,DC=ssa,DC=oam,DC=uk,DC=tmo = OSGRP_IP_Transport','CN=Remote Desktop Users,CN=Builtin,DC=ssa,DC=oam,DC=uk,DC=tmo']
for s in arr:
m = re.search(r'^[^=]*=([^,]+)', s)
if (m):
print(s,'-->',m.group(1))
Prints,
CN=CTX_APP_Bytemobile_UPM,OU=EEGroups,OU=EEOU,DC=ssa,DC=oam,DC=uk,DC=tmo = CTX_APP_Bytemobile_UPM --> CTX_APP_Bytemobile_UPM
CN=OSGRP_IP_Transport,OU=EEGroups,OU=EEOU,DC=ssa,DC=oam,DC=uk,DC=tmo = OSGRP_IP_Transport --> OSGRP_IP_Transport
CN=Remote Desktop Users,CN=Builtin,DC=ssa,DC=oam,DC=uk,DC=tmo --> Remote Desktop Users
x = re.search("(?<=CN=)[\w\s]*", presplit)