import re
regex = re.compile(r"([A-Z]+)", flags=re.MULTILINE)
test_str = ("'coordinatorCountry': 'coordinator_country',\n"
"'ecContribution': 'ec_contribution',\n"
"'ecMaxContribution': 'ec_max_contribution',\n"
"'endDate': 'end_date',\n"
"'frameworkProgramme': 'framework_programme',\n"
"'fundingScheme': 'funding_scheme',\n"
"'participantCountries': 'participant_countries',\n"
"'projectUrl': 'project_url',\n"
"'startDate': 'start_date',\n"
"'totalCost': 'total_cost',\n"
"'activityType': 'activity_type',\n"
"'ecCContribution': 'ec_contribution',\n"
"'endOfParticipation': 'end_of_participation',\n"
"'organizationUrl': 'organization_url',\n"
"'postCode': 'post_code',\n"
"'shortName': 'short_name',\n"
"'vatNumber': 'vat_number',\n"
"'projectID': 'project_id',")
subst = "_\\L$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