繁体   English   中英

如果数字之间未出现句点[。]和逗号[,],则从字符串中删除它们

[英]Remove period[.] and comma[,] from string if these does not occur between numbers

我只想在数字之间没有出现逗号和句点的情况下才删除它们。

因此,以下文字应返回

"This shirt, is very nice. It costs DKK ,.1.500,00,."

"This shirt is very nice It costs DKK 1.500,00"

我尝试过

text = re.sub("(?<=[a-z])([[$],.]+)", " ", text) 

但它不能替代文本中的任何内容。

您可以尝试以下方法:

>>> s = "This shirt, is very nice. It costs DKK ,.1.500,00,."
>>> re.sub('(?<=\D)[.,]|[.,](?=\D)', '', s)
'This shirt is very nice It costs DKK 1.500,00'

使用正向后断言来检查符号由一个非数字字符之前,并且在使用正前向断言来检查它相同的字符集的交替后跟一个非数字字符。

https://regex101.com/r/54STMM/4

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM