Perocat
Perocat

Reputation: 1521

Regex: replace all with '' except lowercase

I have a string, e.g. /test/ and I'd like to mantain only the lowercase. How can I do it with preg_replace?

$string = '/test/';
$new_string = preg_replace('?????', '', $string);
$new_string = 'test';

Upvotes: 1

Views: 306

Answers (1)

Justin Morgan
Justin Morgan

Reputation: 30690

It's simpler than you think:

$string = preg_replace('/[^a-z]/', '', $string);

Upvotes: 5

Related Questions