Guilherme Freire
Guilherme Freire

Reputation: 372

preg_replace with () characters

I want to use preg_replace to clean a string but I want to contine with this character () - Parentheses

I'm using this code

$string = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $string);
$string = preg_replace('/[^\p{Latin}\d ]/u', '', $string);

I want to remove everything except the parentheses letters and numbers

Upvotes: 0

Views: 342

Answers (1)

user2493235
user2493235

Reputation:

If I understand you correctly, use:

/[^\p{Latin}0-9()]/u

That will match anything that is not parentheses, letters or numbers.

So the full code:

$string = preg_replace('/[^\p{Latin}0-9()]/u', '', $string);

Upvotes: 2

Related Questions