You have added ^
and $
which means it would only match at the beginning or end of string. So you need to remove them:
/(([^a-zA-Z0-9$¢£€¥])*|([^a-zA-Z0-9$¢£€¥])*)/
This means your regex could be simplified to:
/[^a-zA-Z0-9$¢£€¥]*/
Now let's improve it further. You never want to replace an empty string with nothing. So let's change the quantifier from *
(zero or more times) to +
(one or more times):
/[^a-zA-Z0-9$¢£€¥]+/
You'll notice that this also removes spaces, so let's exclude it as well:
/[^a-zA-Z0-9$¢£€¥ ]+/
If you want to make it shorter, let's use the i
modifier to match case insensitive and remove A-Z
:
/[^a-z0-9$¢£€¥ ]+/i
After some debugging, it seems we need to handle utf/unicode problems. So let's add the u
modifier like nhahtdh said:
/[^a-z0-9$¢£€¥ ]+/ui
To test this, you will also need to set the encoding for your HTML page. A simple example would look like this:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<?php
$product_name = '£5 off bookings at A1Travel';
echo 'Product Name :: ' . $product_name . '<br>';
$product_name = preg_replace('/[^a-z0-9$¢£€¥ ]+/ui', '', $product_name);
echo $product_name . '<br>';
?>
</body>
</html>
regex demo