MST
星途 面试题库
面试题:Python字符串操作之正则替代方案 - 基础应用
在Python中,假设你有一个字符串 'hello 123 world 456',想要用正则的替代方案将其中所有数字替换为空字符串,应该如何实现?请用代码示例说明。
41.9万 热度
难度
编程语言
Python
知识考点
面试题答案
一键面试
import re s = 'hello 123 world 456' result = re.sub(r'\d+', '', s) print(result)