其他分享
首页 > 其他分享> > 使用 re.sub 转换字符串大小写

使用 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)

标签:lower,sub,s2,re,大小写,inputStr,replacedStr
来源: https://www.cnblogs.com/niucunguo/p/15545223.html