简体   繁体   中英

preg_replace regex for removing product sizes from string

I would like to remove a size from titles ie

Shift Fuel Street Motorcycle Riding Shoes Size 10    

to become

Shift Fuel Street Motorcycle Riding Shoes    

so far I have regex to remove grams, centimeters etc. but those are a bit different as digit there are before string, so the pattern for those is:

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

Can you help with modifying pattern above so can work with sizes as in example at the top of this post/question?

many thanks

Removing the size:

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

UPDATE to support "Size: 10":

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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