Honesty Rocks! truth rules.

Preg Replace Problem

HOME      >>       Programming

Tom743

If i have a word like c.........a......t (with the dots in) and i wanted to replace it with cat how would i do it. If i use

<?php$patterns = "/c(*)a(*)t/";$replace = "cat";echo preg_replace($patterns, $replace, 'c.....a.........t');[/color][color="#000000"]?>

then when i type something like "come and look at this" is also filtered. Is there any way just to filter cat with dots in?

truefusion

If all you want to do is eliminate dots found specifically inbetween the letters "c", "a" and "t", then the following should work:

$patterns = "/c\.{2,}a\.{2,}t/";$replace = "cat";echo preg_replace($patterns, $replace, 'c.....a.........t');
Anything else would require a more complex pattern.