python re.>>> re.sub('asdf','ITEEDU',s,re.I) 'ITEEDUITEEDUasdf' 只能匹配两个>>> s='asdfasdfasdf'>>> re.sub('asdf','ITEEDU',s)'ITEEDUITEEDUITEEDU'无re.>>> re.sub('asdf','ITEEDU',s,re.I)'ITEEDUITEEDUasdf'有re.I只能匹配两个
来源:学生作业帮助网 编辑:作业帮 时间:2024/08/31 03:08:18
![python re.>>> re.sub('asdf','ITEEDU',s,re.I) 'ITEEDUITEEDUasdf' 只能匹配两个>>> s='asdfasdfasdf'>>> re.sub('asdf','ITEEDU',s)'ITEEDUITEEDUITEEDU'无re.>>> re.sub('asdf','ITEEDU',s,re.I)'ITEEDUITEEDUasdf'有re.I只能匹配两个](/uploads/image/z/7253737-25-7.jpg?t=python+re.%3E%3E%3E+re.sub%28%27asdf%27%2C%27ITEEDU%27%2Cs%2Cre.I%29+%27ITEEDUITEEDUasdf%27+%E5%8F%AA%E8%83%BD%E5%8C%B9%E9%85%8D%E4%B8%A4%E4%B8%AA%3E%3E%3E+s%3D%27asdfasdfasdf%27%3E%3E%3E+re.sub%28%27asdf%27%2C%27ITEEDU%27%2Cs%29%27ITEEDUITEEDUITEEDU%27%E6%97%A0re.%3E%3E%3E+re.sub%28%27asdf%27%2C%27ITEEDU%27%2Cs%2Cre.I%29%27ITEEDUITEEDUasdf%27%E6%9C%89re.I%E5%8F%AA%E8%83%BD%E5%8C%B9%E9%85%8D%E4%B8%A4%E4%B8%AA)
python re.>>> re.sub('asdf','ITEEDU',s,re.I) 'ITEEDUITEEDUasdf' 只能匹配两个>>> s='asdfasdfasdf'>>> re.sub('asdf','ITEEDU',s)'ITEEDUITEEDUITEEDU'无re.>>> re.sub('asdf','ITEEDU',s,re.I)'ITEEDUITEEDUasdf'有re.I只能匹配两个
python re.>>> re.sub('asdf','ITEEDU',s,re.I) 'ITEEDUITEEDUasdf' 只能匹配两个
>>> s='asdfasdfasdf'
>>> re.sub('asdf','ITEEDU',s)
'ITEEDUITEEDUITEEDU'
无re.
>>> re.sub('asdf','ITEEDU',s,re.I)
'ITEEDUITEEDUasdf'
有re.I只能匹配两个
python re.>>> re.sub('asdf','ITEEDU',s,re.I) 'ITEEDUITEEDUasdf' 只能匹配两个>>> s='asdfasdfasdf'>>> re.sub('asdf','ITEEDU',s)'ITEEDUITEEDUITEEDU'无re.>>> re.sub('asdf','ITEEDU',s,re.I)'ITEEDUITEEDUasdf'有re.I只能匹配两个
因为re.sub有五个参数:
re.sub(pattern,repl,string,count=0,flags=0)
你在第四个参数写re.I相当于把count设成了2,所以只替换2次.
应该写成:
re.sub('asdf','ITEEDU',s,0,re.I)
或者
re.sub('asdf','ITEEDU',s,flags=re.I) # 推荐