I want to remove all non Arabic, non English and non Numbers charecters from a string, except for dashes (-).
I managed to do it for non English alphanumeric characters like this:
$slug = ereg_replace('[^A-Za-z0-9-]', '', $string);
But for non arabic alphanumeric characters i tried to do it like this:
$slug = ereg_replace('\p{InArabic}', '', $string);
but it didnt strip the non alphanumeric characters! I also tried this answer but it didnt work either, it always returns '0' !!
$slug = preg_replace('/[^\x{0600}-\x{06FF}A-Za-z0-9-]/u','', $string);
Hopefully someone can help me.
The approach is to use the String. replaceAll method to replace all the non-alphanumeric characters with an empty string.
How do you remove non letters from a string in Python? Use the isalnum() Method to Remove All Non-Alphanumeric Characters in Python String. Use the filter() Function to Remove All Non-Alphanumeric Characters in Python String. Use Regular Expressions to Remove All Non-Alphanumeric Characters in Python String.
Here in our tutorial, let us do this using isalnum(). We can also do this using regular expressions and isalpha(), isnumeric(). Most importantly, we use isalnum() because it is the easiest way to delete alphanumeric elements from the list.
Try the below:
$slug = preg_replace('/[^\p{Arabic}\da-z-]/ui', '', $string);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With