# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(?<=CN\=).*?(?=,)"
test_str = ("Computer Location = afp.local/EANG\n"
"Description = RED_TXT\n"
"Device Name = EANG04W\n"
"Domain Name = afp.local\n"
"Full Name = Admintech\n"
"Hardware Monitoring Type = ASIC2\n"
"Last Blocked Application Scan Date = 1420558125\n"
"Last Custom Definition Scan Date = 1348087114\n"
"Last Hardware Scan Date = 1420533869\n"
"Last Policy Sync Date = 1420533623\n"
"Last Software Scan Date = 1420533924\n"
"Last Update Scan Date = 1420558125\n"
"Last Vulnerability Scan Date = 1420558125\n"
"LDAP Location = **CN=EANG04W**,OU=EANG,DC=afp,DC=local\n"
"Login Name = ADMINTECH\n"
"Main Board OEM Name = Dell Inc.\n"
"Number of Files = 384091\n"
"Primary Owner = **CN= LOUHICHI anoir**,OU=EANG,DC=afp,DC=localenter code here")
subst = "Company"
# You can manually specify the number of replacements by changing the 4th argument
result = re.sub(regex, subst, test_str, 0, re.MULTILINE | re.IGNORECASE)
if result:
print (result)
# Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Python, please visit: https://docs.python.org/3/library/re.html