import re  
# 使用sub函数  
text = "hello world, hello everyone"  
new_text = re.sub("hello", "hi", text)  
print(new_text)  # 输出: hi world, hi everyone  
# 使用subn函数  
new_text, count = re.subn("hello", "hi", text)  
print(new_text)  # 输出: hi world, hi everyone  
print(count)     # 输出: 2，表示替换了两次
