文章详情页
python - 删除txt文件内所有<>里面的内容包括<>本身。
浏览:241日期: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. php study 安装 composer 用不了2. mysql sql where id in(25,12,87) 结果集如何用按照 25 12 87排序?3. mysql - SELECT 多個資料表及多個欄位4. 登录界面URL在服务器上无法找到5. php链接数据库,mysql_connect 无法使用6. mysql - 这条联合sql语句哪里错了7. mysql多表查询8. spring - mysql中事务是互斥的么?9. 微信渠道二维码怎么使用?10. 创建数据表错误: You have an error in your SQL syntax; check the manual that corresponds to your MySQL serve
排行榜

网公网安备