Possible duplicate:Replace multiple spaces with a single space in Python
trying to figure out how to write a regular expression that is given for a string:
"hi this is a test"
I can turn it into
where spaces are normalized to only one space
any ideas? Many thanks
import re re.sub("\s+"," ",string)
Do I need to be a regular expression?
I would just use
new_string = " ".join(re.split(s'\s+', old_string.strip()))
Sed
sed 's/[ ]\{2,\}/ /g'
Source: https://habr.com/ru/post/1748600/More articles:Help Connecting an elevator to an Oracle database - oracleКаков наилучший способ обернуть некоторый текст в тег xml? - c#You can get the tcp port website - c #Python win32com opens Excel with Bloomberg plugin - pythonwhich is the best javascript library for creating canvas compatible with IE - javascriptWrite the data in cmd to memory instead of the file, catch it with C # - command-lineHow to Build a List Set - wolfram-mathematicaCMake cyclic dependency error when user library name matches system library name - c ++How to update selective fields in SQL (leaving unchanged)? - sqlActiveRecord without tuning database tables? (declarative like Django) - databaseAll Articles