srmeile
srmeile

Reputation: 468

Regex remove everything after Regex Match

$str = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $str);

I have this code, this removes all encoded chars, how can I make it remove everything after the first match (including the first match)

Upvotes: 2

Views: 76

Answers (1)

Barmar
Barmar

Reputation: 781096

Use a wildcard in the regexp:

$str = preg_replace('/[\x00-\x1F\x80-\xFF].*/', '', $str);

Upvotes: 4

Related Questions