File size: 385 Bytes
dab2de2
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
"""Insert spaces, mypython/split_chinese.py."""
import re


def insert_spaces(text: str) -> str:
    """Insert space in Chinese characters.

    >>> insert_spaces("test亨利it四世上")
    ' test 亨 利 it 四 世 上 '
    >>> insert_spaces("test亨利it四世上").strip().__len__()
    17

    """
    return re.sub(r"(?<=[a-zA-Z\d]) (?=[a-zA-Z\d])", "", text.replace("", " "))