import re
regex = re.compile(r"(?:\G(?!\A)|^(?!.*\.join\.))(.*?)PD_", flags=re.MULTILINE)
test_str = ("it.mycompany.db.beans.str1.PD_T_PD_CLASS\n"
"it.mycompany.db.beans.join.PD_T_CLASS\n"
"it.mycompany.db.beans.str2.PD_T_CLASS_1\n"
"it.mycompany.db.beans.join.PD_T_CLASS_1\n"
"PD_T_CLASS myVar = new PD_T_CLASS();\n"
"myVar.setPD_T_CLASS(something);")
subst = "$1"
result = regex.sub(subst, test_str)
if result:
print(result)
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