Python/Django: How to remove extra white spaces & tabs from a string?

后端 未结 6 2165
天命终不由人
天命终不由人 2020-12-29 21:59

I\'m building a website with Python/Django. Users submit tags. Each tag can contain multiple words. Each tag has an ID number. I want to make sure tags that are formatted sl

6条回答
  •  抹茶落季
    2020-12-29 23:02

    >>> import re
    >>> re.sub(r'\s+', ' ', 'some   test with     ugly  whitespace')
    'some test with ugly whitespace'
    

提交回复
热议问题