How do I create regex groups for replacement?

Posted by resting on Stack Overflow See other posts from Stack Overflow or by resting
Published on 2011-01-13T02:43:41Z Indexed on 2011/01/13 2:53 UTC
Read the original article Hit count: 306

Filed under:
|
|
|
|

I have this sample string:

Image:  SGD$45.32 SKU: 3f3f3 dfdfd grg4t BP 6yhf Pack Size: 1000's Color: Green Price: SGD$45.32 SGD$45...

I would like to remove all the prices namely:

SGD$45.32  
Price: SGD$45.32  
SGD$45  

I have this expression thats supposed to match the 3 groups:

$pattern = '/(Price.+\sSGD\$\d+\.\d{2})(SGD\$\d+\.\d{2})(SGD\$\d+)/';  
$new_snippet = preg_replace($pattern, '', $snippet);`  

But apparently its not working.

It works if I replace a single group at a time. But, I'd like to know if it possible to replace all possible matching groups with a single statement.

Tried preg_match_all($pattern, $snippet, $matches); to show matches based on the above pattern, but no matches are found if I put all 3 groups together.

© Stack Overflow or respective owner

Related posts about php

Related posts about regex