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,})] /","",$str ing);
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.
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,}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
(The pipe character acts as a logical OR)
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.