Search code examples
iosregexlocalizationarabicnsregularexpression

iOS regular expression arabic


I come from this posts

Regular Expression Arabic characters and numbers only

How to match arabic words with reg exp? (didn't answer my question)

I've tried

^[\p{Arabic} ]+$

and received

'Parse error', reason: 'Invalid escape sequence @ pos 3: ^[\ ▶p{Arabic} ]+$'

I've also tried

^[\u0621-\u064A\s]+$

'Parse error', reason: 'Invalid character range @ pos 7: ^[\u062 ▶1-\u064A\s]+$'

I've also tried

^[\u0621-\u064A]+$

'Parse error', reason: 'Invalid character range @ pos 7: ^[\u062 ▶1-\u064A]+$'

I need ^[A-Za-z ]+$ that accepts arabic characters.

Thanks in advance!


Solution

  • This solved my issue

    Arabic text with spaces only:

    ^[ء-يء-ي ]+$

    Arabic text only:

    ^[ء-ي]+$

    Arabic text and digits:

    ^[ء-ي٠-٩]+$

    for English text and arabic text

    ^[A-Za-zء-ي]+$

    for English and Arabic Text and digits

    ^[A-Za-z0-9ء-ي٠-٩]+$

    It will crash if you use unicode