Tuesday, 15 January 2013

python - Non-greedy operator on re.sub -



python - Non-greedy operator on re.sub -

given next string:

>>> s = 'claude binyon [director / screenwriter] walter benjamin hare [play author]'

i want accomplish following:

'claude binyon,walter benjamin hare,'

i have next regex, greedy, replacing after [. how create next non-greedy work needed?

>>> re.sub('\[.+]',',',s) 'claude binyon ,'

try doing :

>>> re.sub('\[.+?]',',',s)

python regex

No comments:

Post a Comment