python代码:
import re def remove_space_between_cn_en(text): strArray = re.split(' ',text) if len(strArray) < 2: return text result = '' for t in strArray: if t=='': continue if re.search('[a-zA-Z0-9]$',result) and re.search('^[a-zA-Z0-9]',t): result = result + ' ' + t else: if not result=='': result = result + t else: result = t return result s = "你 好 Hello World 世 界" print(remove_space_between_cn_en(s))
输出结果:
你好Hello World世界标签:中文,python,text,strArray,空格,re,result From: https://www.cnblogs.com/yellow3gold/p/17702985.html