preg_replace regex用于从字符串中删除产品大小

时间:2011-08-03 08:21:36

标签: php regex

我想删除标题中的大小,即

Shift Fuel Street Motorcycle Riding Shoes Size 10    

成为

Shift Fuel Street Motorcycle Riding Shoes    

到目前为止,我有正则表达式来删除克数,厘米数等但是这些数字与字符串之前的数字有点不同,所以这些模式是:

preg_replace('/(?<!\S)(\b|\(|\[)?\d+(?:\.\d+)?\s*cm($|\s|\.|;|,|\)|\])/is', '${1}${2}', $string);

您可以帮助修改上面的模式,因此可以使用这个帖子/问题顶部的示例吗?

非常感谢

1 个答案:

答案 0 :(得分:2)

删除尺寸:

preg_replace("/\s+Size\s+\d+/", '', $text);

更新以支持“尺寸:10”:

preg_replace("/\s+Size:?\s+\d+/", '', $text);