Strip punctuation from a string with regex using PHP

A quick regex snippet on how to match punctuation on a string and strip them out.

// To keep letters & numbers
$string = preg_replace('/[^a-z0-9]+/i', '_', $string);
 
// To keep letters only
$string = preg_replace('/[^a-z]+/i', '_', $string);
 
// To keep letters, numbers & underscore
$string = preg_replace('/[W]+/', '_', $string);

Source