使用 re.sub 转换字符串大小写

import re

def pythonReSubDemo(inputStr):
"""
demo Pyton re.sub
"""
# inputStr = "recordInvalidDate"

def to_lower(matched):
    s = matched.group(0).lower()
    t = f'_{s}'
    return t

replacedStr = re.sub(r"([A-Z])", to_lower, inputStr)
print("replacedStr=", replacedStr)    # record_invalid_date

if name == "main":
s1 = """
organizationName,parkCode,parkAddress, parkNature, parkRegionId1, parkRegionId2,'
' parkType,parkClass, parkLon, parkLac, spaceLoc, isShared, sharedParkPlaceNum, parkStage,'
' stageDate,berths, openParkPlaceNum, chargeNum, entranceNum, exitNum, licence, sentDateTime,'
' recordEffectDate,recordInvalidDate, tsaaFee, tbaaFee, daySmallCarChrononMinsFirstHour,'
'chargingStandardTempSmallCarDayFirstHour

"""
s2 = s1.split(',')
for i in s2:
    pythonReSubDemo(i)
上一篇:【转载】EXCEL VBA 工作簿(表)合并拆分


下一篇:python-mqtt自动化测试