题解 | #表示数字#
表示数字
https://www.nowcoder.com/practice/637062df51674de8ba464e792d1a0ac6
#print(ord('A'),ord('0')) ''' s=list(input()) s1='' pre_s='' for i in s: if i.isdigit(): if pre_s.isdigit()==0: s1 += '*' else: if pre_s.isdigit(): s1 += '*' s1 += i pre_s = i if s[-1].isdigit(): s1 += '*' print(s1) ''' ''' while True: try: s = input() sn = '' s = s.replace('*', '&') for i in s: if i.isdigit(): sn += '*' + i + '*' else: sn += i sn = sn.replace('**', '') print(sn.replace('&', '*')) except: break ''' import re while True: try: print(re.sub('(\d+)', '*\g<1>*', input())) ''' re.sub(目标字段i,新字段j,所在字符串s) 将s中的i替换为j \d 任意0-9数字 + 匹配+前面一次或多次 \d+ 一个数字或多个数字 \g<1> sub()的group替换,指代前组的第1个字段 \g<1>\g<2>\g<3> ''' except: break