【发布时间】:2017-11-07 22:44:37
【问题描述】:
假设您有一组非常嘈杂的文本,并且您希望每次都选择一个定义的模式,例如\d{3}(?:\.||\s)\d{3}。问题是,这种模式可能出现在许多情况下,例如"443 440 $"、"923 140 €"、"923 140 EUR"、"product id 001 012"、"id prod. 001 012"、"product 001 012" 是否出现在相同的文本中。
正如我们所看到的,该模式匹配所有这些。
例如:
text1 = "Here it is simple because my text includes only one regexp matching which is 443 440 ID"
text2 = "But in some other texts, the regexp can be corresponding to a product profit 956.000 EUR for the product ID 001 023"
text3 = "Also, it can be found that the product 001.079 has a profit of 900 000 $USD"
text4 = "It can be analyzed that the 001789 product contains 001 000 components"
在这里我想确定我收集的是正确的东西:产品 ID [443 440, 001 023, 001.079, 001789]
你会怎么处理?
在现实世界中,可以发现一些特征可能有助于确定数字是否真的是产品ID(正则表达式在文本中的位置-一般在开头,常量判别词-EUR $, ...)
【问题讨论】:
标签: python regex machine-learning