作者detic (dadi)
看板Python
标题[问题] *
时间Tue Dec 27 22:07:40 2016
不好意思请教,我刚接触python,
想请问在字串中的*(万用替代字)该如何使用?
比方说
a=["abc","aba","abj","asd","aja"]
想要移除其中头尾有a的项目,
直观地想
a.remove("a*a")
.....是不行的....
请问在python中要如何操作我的想法
感谢:)
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 119.14.71.105
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1482847663.A.B91.html
1F:推 Sunal: re regular expression 12/27 22:19
2F:→ yjc1: fnmatch 12/27 22:19
3F:推 Yshuan: 就算是RE也是a.*a吧 ... 12/27 22:46
4F:→ kenduest: re 的话 ^a.*a$ 应该更符合需求? 12/28 00:23
5F:→ kenduest: new_a = [i for i in a if re.match("^a.*b$",i)] 这样? 12/28 00:32
6F:→ kenduest: 上面是抓符合的,稍微改一下加上 not 就变成不符合 12/28 09:42
8F:推 kenduest: glob不是用於档案搜寻比对吗? 01/03 11:50