Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
很抱歉,我很早就对正则表达式很陌生。
我怎样才能从这种字符串 /projects/myproject/ 中获得以下 2 个元素(projects,myproject)?
输出 :
print group1 : 'projects' print group2 : 'myproject'
谢谢
my_str = "/projects/myproject/" matches = re.findall("/(.+?)/(.+)/",my_str) print matches #prints ['projects','myproject']