How to detect whether a character belongs to a Right To Left language?

前端 未结 5 1353
失恋的感觉
失恋的感觉 2020-11-28 06:02

What is a good way to tell whether a string contains text in a Right To Left language.

I have found this question which suggests the following approach:



        
5条回答
  •  被撕碎了的回忆
    2020-11-28 06:26

    EDIT:

    This is what I use now, it includes the Vowelization chars and everything in Hebrew and Arabic:

    [\u0591-\u07FF]
    

    OLD ANSWER:

    If you need to detect RTL language in a sentence, this simplified RegEx will probably be enough:

    [א-ת؀-ۿ]
    

    If one wants to write something in Hebrew it will have to use one of these characters, and the case is similar with Arabic.

    It does not include vowelization characters, so if you need to catch all whole words or absolutely all RTL chars you better use one of the other answers. Vowelization chars in Hebrew are very rare in non-poetry texts. I don't know about Arabic texts.

提交回复
热议问题