Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在字符串python中查找模式_Python - Fatal编程技术网

在字符串python中查找模式

在字符串python中查找模式,python,Python,我有一个非常嘈杂的字符串输入,我正在尝试清理它 因此,嘈杂的字符串的一部分可能类似于: "big $price chair, 5x10" 现在删除符号和其他东西都完成了! 但我也想删除 5x10 为此,我这样做: def remove_numerics(self,string): return ' '.join([term for term in string.split() if not term[0].isdigit()]) 谁解决了这个案子 但如果我的字符串是:

我有一个非常嘈杂的字符串输入,我正在尝试清理它

因此,嘈杂的字符串的一部分可能类似于:

"big $price chair, 5x10"
现在删除符号和其他东西都完成了! 但我也想删除

  5x10
为此,我这样做:

 def remove_numerics(self,string):
    return ' '.join([term for term in string.split() if not term[0].isdigit()])
谁解决了这个案子

但如果我的字符串是:

    "big $price chair, x10"
那么它失败了? 解决这个问题的好办法是什么。
非常感谢。

所以您想删除NUMBERSxNUMBERS?+1表格中的所有“单词”。次要的挑剔:永远不要以python内置代码命名变量。将
str
更改为其他内容。@JoelCornett谢谢。。。整个星期都在写C#。。。将其切换到错误的方向>。
re.sub(r'\b[\dx]+\b', '', "big $price chair, 5x10")
import re
new_string = re.sub(r', \d*x\d+', '', old_string)