文章详情页
python - 删除txt文件内所有<>里面的内容包括<>本身。
浏览:62日期:2022-08-23 15:34:32
问题描述
删除txt文件内所有<>里面的内容包括<>本身。该怎么写?卡在对字符串的处理那里。
问题解答
回答1:大概是這樣:
使用 re.sub 把 <...> 取代為空白:
# python3 codeimport re# for examples = ’123<><here>#$%@#$%^<123>::<a href='http://www.hello.com'>haha’print(re.sub(’<[^>]*>’, ’’, s))# read txt and remove all <...>with open(’your.txt’, ’r’) as reader: for line in reader:line = line.strip()print(re.sub(’<[^>]*>’, ’’, line))
範例字串取代結果:
123#$%@#$%^::haha
我回答過的問題: Python-QA
相关文章:
1. macos - mac下docker如何设置代理2. java - 请问在main方法中写成对象名.属性()并赋值,与直接参参数赋值输错误是什么原因?3. MySQL数据库中文乱码的原因4. 关docker hub上有些镜像的tag被标记““This image has vulnerabilities””5. docker不显示端口映射呢?6. docker - 各位电脑上有多少个容器啊?容器一多,自己都搞混了,咋办呢?7. android studio总是在processes running好久8. angular.js - 关于$apply()9. docker-compose 为何找不到配置文件?10. dockerfile - 我用docker build的时候出现下边问题 麻烦帮我看一下
排行榜
