# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(?mi)((?:password=|user=)[^\n]*$|\<property key=\"variableNames\"\/\>\n|\<property key=\"variableValues\"\/\>\n)"
test_str = ("<maplayer simplifyAlgorithm=\"0\" minimumScale=\"0\" maximumScale=\"2500\" simplifyDrawingHints=\"0\" readOnly=\"0\" minLabelScale=\"0\" maxLabelScale=\"1e+08\" simplifyDrawingTol=\"1\" geometry=\"Point\" simplifyMaxScale=\"1\" type=\"vector\" hasScaleBasedVisibilityFlag=\"1\" simplifyLocal=\"1\" scaleBasedLabelVisibilityFlag=\"0\">\n"
" <id></id>\n"
" <datasource>port=1521 user=test_user password=test_passwd</datasource>\n"
" <keywordList>\n"
" <value></value>\n"
" </keywordList>\n"
" <featformsuppress>0</featformsuppress>\n"
" <editorlayout>generatedlayout</editorlayout>\n"
" <widgets/>\n"
" <conditionalstyles>\n"
" <rowstyles/>\n"
" <fieldstyles/>\n"
" </conditionalstyles>\n"
" </maplayer>\n"
" </projectlayers>\n"
" <properties>\n"
" <Variables>\n"
" <variableNames type=\"QStringList\">\n"
" <value>paswd</value>\n"
" <value>user</value>\n"
" </variableNames>\n"
" <variableValues type=\"QStringList\">\n"
" <value>5zdgf</value>\n"
" <value>dgdgdgfdg</value>\n"
" </variableValues>\n"
" </Variables>\n"
" <customproperties>\n"
" <property key=\"labeling/textColorR\" value=\"0\"/>\n"
" <property key=\"labeling/textTransp\" value=\"0\"/>\n"
" <property key=\"labeling/upsidedownLabels\" value=\"0\"/>\n"
" <property key=\"labeling/useSubstitutions\" value=\"false\"/>\n"
" <property key=\"labeling/wrapChar\" value=\"\"/>\n"
" <property key=\"labeling/xOffset\" value=\"0\"/>\n"
" <property key=\"labeling/yOffset\" value=\"0\"/>\n"
" <property key=\"labeling/zIndex\" value=\"0\"/>\n"
" <property key=\"variableNames\"/>\n"
" <property key=\"variableValues\"/>\n"
" </customproperties>")
subst = ""
# You can manually specify the number of replacements by changing the 4th argument
result = re.sub(regex, subst, test_str, 0)
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