You can check if your Regex flavour supports \p{Arabic}
or \p{InArabic}
try:
$regex = '[\p{Arabic}\d-\[\]_+ ]+'
سؤال
I want to know the equivalent of the following, but for Arabic alphabet only:
$regex = '[A-Za-z0-9-[\]_+ ]+'
I tried:
$regex = '[ا-ئ0-9 ]+';
In which the first Arabic letter ا
and the last one ئ
. However, I have got the following error:
[phpBB Debug] PHP Warning:
in file [ROOT]/includes/functions_user.php on line 1505: preg_match():
Compilation failed: range out of order in character class at offset 6
المحلول
You can check if your Regex flavour supports \p{Arabic}
or \p{InArabic}
try:
$regex = '[\p{Arabic}\d-\[\]_+ ]+'
نصائح أخرى
You can begin to find the answer to your own question by taking a look and briefly reading the following:
An equivalent regular expression would be the following:
~[\p{Arabic}\d[\]_+ -]+~u
Regular expression
[\p{Arabic}\d[\]_+ -]+ any character of: UTF macro 'Arabic',
digits (0-9), '[', '\]', '_', '+', ' ', '-'
(1 or more times (matching the most amount possible))
By adding the u
modifier to the end of the regular expression, the Pattern strings are treated as UTF-16 and this also causes escape sequences to match unicode characters.
On a further note, by using \p{N}
it will allow you to match any kind of numeric character in any script.
[\p{Arabic}\p{N}[\]_+ -]+
Note: It's more common to find a hyphen -
placed first or last within a character class or choosing to escape it instead.