【问题标题】:How to remove white space between digit in string sentences python如何删除字符串句子中数字之间的空格python
【发布时间】:2021-08-31 19:53:49
【问题描述】:

我有句子。

Sent = [“my contact number is 011 45 5554”,”my new contact number 034 543 4543”]

我需要它是这样的:

Sent = [“my contact number is 011455554”,”my new contact number 0345434543”]

只删除数字之间的空格

【问题讨论】:

标签: python-3.x string list nlp python-re


【解决方案1】:
import re

regex = r"(\d+)\s(\d+)\s(\d*)"

text = "my contact number is 011 45 5554”,”my new contact number 034 543 4543"
text = re.sub(regex, "\\1\\2\\3", text)

print (text)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-23
    • 2018-05-15
    • 2015-04-27
    • 2023-01-31
    • 2018-12-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多