for example I have following string:
a_b__c___d____e
How to preg_replace char _ to char ‘-‘, but only if part ‘ __…’ contains more than N repeated _.
I hope you understand me ))
source: a_b__c___d____e
cond: change '_' where 2 or more
result: a_b--c---d----e
or
source: a_b__c___d____e_____f
cont: change '_' where 4 or more
result: a_b__c___d----e-----f
Thanks!
p.s. Interesting solution without using loops. How implement it with loops (I think) know anybody. Just a one regex and preg_replace.
Here is another one using the
emodifier:Replace
4by the number you need. Or as function: