Link to home
Start Free TrialLog in
Avatar of foxymoron7
foxymoron7

asked on

PHP Regex for mixed quantities of consecutive characters

Hi all,

I want to match varying quantities of consecutive characters in a string.  
For example, in $string I want to replace with nothing (i.e. ""):
any number of instances (consecutive or not) of !@#
and replace instances of 2 or more consecutive -
and replace instances of 3 or more consecutive +

Example:
$string='d+++og! + ca#t@ - how about the m--ule';
 I'd like to do something like:
echo preg_replace("/[!@#(\-{2,})(\+{3,})]/","",$string);
to get "dog + cat - how about the mule"

Every variant of moving/removing the parentheses and brackets that I've tried replaces either all instances of - and + including where they only occur once, or replaces no instances at all.

Thank you in advance.


ASKER CERTIFIED SOLUTION
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
(The pipe character acts as a logical OR)
Avatar of foxymoron7
foxymoron7

ASKER

Thank you TerryAtOpus!  I'm glad I forgot to mention that I had also tried using the | with no success.  Obviously, I screwed something up when I tried it before.  You are a champion.