PROGRAMMING

 
REMEMBERS




Last update:   29-10-2021

Add paranteses

Find and add paranteses to matches.
 
$str = "Find gray or grey";

echo preg_replace('/(gr[ae]y)/', '( $1 )', $str);

//Outputs: Find ( gray ) or ( grey )    
Replace Double Words    (2/2)

Replace double words

Find and replace double words.
 
$str = "word word";

echo preg_replace("/\b([a-zA-Z]+) +\1\b/", "$1", $str); 

    // double backslashes \1, not one
// outputs: word

Questions    
Special chars

        A B C D E F
🔔
1/2