Forum Moderators: coopster
preg_replace('([&]+[a-zA-Z0-9]+.[;]+)', '_', $string); preg_replace('([&]+[a-zA-Z0-9]{4-6}+.[;]+)', '_', $string); The curly brackets (braces) are commonly referred to as min/max quantifiers. You can read more about them on the PCRE Pattern Syntax [php.net] page.
preg_replace('%&[a-z0-9]{4,6};%i', '_', $input);
That is funny as this
preg_replace('/([&]+[a-zA-Z0-5]{4,6}+[;])/', '_', $string);
The + means 1 or more so your regex will match
&&&&&&&&&&&&&&&&&&&&&&&&&&this; because of the [&]+
However as you have a + after your {4,6} you may find that your regex will also match any group of 4-6 characters that is repeated i.e.
&thisthisthisthisthisthisthisthis;
I haven't tried it, to see if the match above will work but you dont need that + after the {}. As the {} give min and max...but with the + you are also saying 1 or more.
The () are for a capturing sub pattern, so in this case you are not worried about capturing anything for use afterwards. So the process will be imperceptibly sped up by not using the ().
Finally the i modified saves you typing [a-zA-Z] as it means case insensitive.
However as well as me not getting the min and max number correct in my first example I also didnt notice that you are not going 0-9. So I guess that I should look more closely ;)