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.
给定以下字符串:
>>> s = 'Claude Binyon [Director / Screenwriter] Walter Benjamin Hare [Play Author]'
我想实现以下目标:
'Claude Binyon,Walter Benjamin Hare,'
我有以下正则表达式,但它很贪心,所以在[. 我将如何根据需要使以下非贪婪工作?
[
>>> re.sub('\[.+]',',',s) 'Claude Binyon ,'
尝试这样做:
>>> re.sub('\[.+?]',',',s)