Mirkamol Temirkulov
Mirkamol Temirkulov

Reputation: 31

Remove all Right to Left Characters in discord.js leaderboard

Hello there I just wanted to ask if there is a way to remove all right-to-left characters. I am aware of .replace(/\u200f/g, "") and .replace(/[^\x00-\x7F]/g, "") but they have not really helped with my leaderboards since the former still doesn't remove the rtl characters and the latter only removes all non-ascii characters which also involves characters that aren't written from left to right. if there was a possible fix for replacing all characters from languages that are read from right to left, i would be very grateful

Here is the sample input

acc.tag.replace(/\u200f/g, "")

and here is the sample output

 1. PersonA#1333 - 8052.7x
 2. PersonB#3169 - 8035.3x
 3. PersonC#7619 - 7541x
PersonD#7797 - 7529.5x.𞠔𞠔 4

or when I do .replace(/[^\x00-\x7F]/g, "") it outputs the following(sample):

 4. PersonA#1333 - 8052.7x
 5. PersonB#3169 - 8035.3x
 6. PersonC#7619 - 7541x
 4. #4327 - 6553.4x

in the above scenario, it replaced 𝐁𝐫𝟎𝐰𝐧𝐏𝟑𝐚𝐜𝐡 as "" since it consists of non ASCII characters but its not a rtl text.

Upvotes: 3

Views: 175

Answers (1)

Compositr
Compositr

Reputation: 737

I think you're looking for this RegExp /[\u04c7-\u0591\u05D0-\u05EA\u05F0-\u05F4\u0600-\u06FF]/gi.

It matches both Hebrew and Arabic, and doesn't match Emojis or special non-RTL Unicode characters. See the regexr tests here

Upvotes: 1

Related Questions