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

前端 未结 5 1316
失恋的感觉
失恋的感觉 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:21

    On my implementation of regex I could not use neither \u, \x, nor {} language named groups.

    So I built my own pattern programatically based on all "R" and "AL" (RandALCat) bidirectional characters as listed in UnicodeData.txt.

    [־׀׃א-״؛-ي٭-ە‏ײַ-ﳝﶈ-ﷺﺂ-ﻼ]
    

    This should be decently comprehensive and I've tested it on Arabic and Hebrew text so far.

提交回复
热议问题