-
查找空行:^[ /t]*$/r/n
-
查找最后一位是小写字母的8位十六进制数:0x[0-9]{7,7}[a-z]{1,1}
-
查找至少有一位是小写字母的8位十六进制数:0x(?=[0-9]{0,7}[a-z])[a-z0-9]{8,8}
-
截取当前行第一个括号前面的全部字符:(?=^[^(|^(^/r|^/n]*[(|(])^[^(|^(]*
import re #查找至少有一位是小写字母的8位十六进制数,并将其修改为大写 def hex_to_upper(hexStr): listHex = re.findall("0x(?=[0-9]{0,7}[a-z])[a-z0-9]{8,8}", hexStr) print listHex newStr = re.sub(r"0x(?=[0-9]{0,7}[a-z])[a-z0-9]{8,8}", "0XLLLLLLLL", hexStr) for obj in listHex: print obj, '-----------', obj[2:] newStr = re.sub(r"0XLLLLLLLL", '0x'+obj[2:].upper(), newStr, 1) return newStr if __name__ == '__main__': a = "oei0x7822CDE2lwnfnsodf0x7822abe2lsdksdf1023900x98de293c988e9we0x98112931ii" print a print hex_to_upper(a)
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/182890.html