Adding quotes to words using regex in Python
Question: I am trying to replace each word in a sentence with the same word but quote
(by word I mean just letters, no numbers) using regex.

For example `4 python code` should be converted to `4 "python" "code"`.

But this code produce the wrong result

    
    
    >>> import re
    >>> s = "4 python code"
    >>> re.sub(r'([a-z]*)', r'"\1"', s)
    '""4"" "python" "code"'
    

Any ideas?


Answer: Change,

    
    
    re.sub(r'([a-z]*)', r'"\1"', s)
    

to

    
    
    re.sub(r'([a-z]+)', r'"\1"', s)
    

