9mm

9mm

Iโ€™m trying to make a regex to remove emojis based on this thread:

This causes an error:

Regex.replace(~r/[\u{1F600}-\u{1F6FF}]/, "๐Ÿ’ฐ Monies! ๐Ÿ’ฒ", "")
# (Regex.CompileError) PCRE does not support \L, \l, \N{name}, \U, or \u at position 2

I tried using \x{FFFF} syntax instead according to this: Regex Tutorial: Introduction to Unicode Regular Expressions

But I get another error:

Regex.replace(~r/[\x{1F600}-\x{1F6FF}]/, "๐Ÿ’ฐ Monies! ๐Ÿ’ฒ", "")
# (Regex.CompileError) character value in \x{} or \o{} is too large at position 9

Apparently I also need u to enable unicode but that doesnt seem to work either:

Regex.replace(~r/[\x{1F600}-\x{1F6FF}]/u, "๐Ÿ’ฐ Monies! ๐Ÿ’ฒ", "")
"๐Ÿ’ฐ Monies! ๐Ÿ’ฒ"

Showing Posts 1 to 10

kip

kip

ex_cldr Core Team

You might have some better luck using the unicode character class So (other symbol). For example:

iex> x = "๐Ÿ’ฐ Monies! ๐Ÿ’ฒ"                                
"๐Ÿ’ฐ Monies! ๐Ÿ’ฒ"
iex> String.replace x, ~r/\p{So}/u, ""
" Monies! "

BTW, the โ€œcorrectโ€ approach to this would be:

iex> String.replace x, ~r/\p{Emoji}/u, ""

But erlangโ€™s re module doesnโ€™t support that character class.

9mm

9mm OP

Interesting.. does that strip other languages or only emojis? I was trying to avoid stripping chinese/japanese/korean, which it seems like a lot of emoji regex do

kip

kip

ex_cldr Core Team

No, it doesnโ€™t. The full list of code points in So are here: Unicode Characters in the 'Symbol, Other' Category

Itโ€™s more permissive than just emoji, but it does not include scripts.

iex> String.replace "ๅพก่จ€ๅฎฃ", ~r/\p{So}/u, ""
"ๅพก่จ€ๅฎฃ"
9mm

9mm OP

Hmm yess, and it also is missing some emoji for some reason. God this is confusing

9mm

9mm OP

Can you try this string?

x = "abcdefghijklmnopqrstuvwxyz....0123456789 ไธๆฅต๏ผŒ็‰ฉ็‰‡้กžๆ›ธ่ปŠ่ฃก๏ผๅไปŠๆžœๅŠๆŽฅๅœ‹ๅ…ˆ้›„ ใƒ‹ใƒƒใƒใƒณใ€ใ€Œใƒ‹ใƒ›ใƒณใ€ไธกๆ–นไฝฟ็”จใ•ใ‚Œใ‚‹ไธญ ใซใฏๆ–‡์ค‘๊ตญ, ์ผ๋ณธ, ๋ฒ ํŠธ๋‚จ ๋“ฑ ํ•œ์ž ๋ฌธํ™”๊ถŒ์— ์†ํ•˜๋Š” ์•„์‹œ์•„ ์—ฌ๋Ÿฌ ๊ตญ๊ฐ€์—์„œ๋Š” ํ•œ๊ตญ์–ด็š„ๅทฎๅผ‚ๅค–๏ผŒ้€šๅธธ่ฎคไธบ่ฟ˜ๅญ˜ๅœจ่ฏๆฑ‡ไธŠ็š„ๅทฎๅผ‚ใ€‚ไพ‹ๅฆ‚็นไฝ“ไธญๆ–‡้‡Œๅคš็”จ็š„โ€œๅŽŸ ู„ู…ู†ุทู‚ุฉ ุงู„ุดุฑู‚ ุงู„ุฃูˆุณุท ู‡ูŠู„ูŠ: ุงู„ุชุญุฑูƒ ุถุฏ ุฅูŠุฑุงู† ุณูŠุจุฏุฃ ู…ู† ู…ุฌู„ุณ ุงู„ุฃู…ู†๐Ÿ“Œโ˜ฎ๏ธ๐Ÿ’Ÿ๐Ÿ”ฏโ˜ช๏ธใŠ—๏ธ๐Ÿˆต๐Ÿ†š๐Ÿ’ฏโ•๐Ÿ”ž๐Ÿšท๐Ÿ”ฐโ‰๏ธโš ๏ธ๐Ÿ’ค๐ŸŒ๐ŸŒ€โ–ถ๏ธ๐Ÿ” ๐Ÿ”ฃโ†”๏ธโ†ฉ๏ธ๐Ÿ‘โ€๐Ÿ—จ๐Ÿ—จ๐Ÿ—จ๐Ÿ—จ๐Ÿ—จ โ—ฝ๏ธ๐Ÿ”ฒ๐Ÿ‡ต๐Ÿ‡ฆ๐Ÿณ๏ธ๐Ÿณ๏ธโ€๐ŸŒˆ๐ŸŒˆ๐ŸŒˆ๐ŸŒˆ๐ŸŒˆ๐Ÿ‡น๐Ÿ‡ฒ๐Ÿ‡น๐Ÿ‡ท๐Ÿค›๐Ÿคœ๐Ÿผ๐Ÿ‘๐Ÿฝ๐Ÿ‘Œโ˜๐Ÿผ๐Ÿฅ๐Ÿฅฆ๐ŸŒถ๐ŸŒฝ๐ŸŽ ๐Ÿฒ๐Ÿ”๐Ÿฅž๐Ÿ๐Ÿ”๐Ÿ—๐ŸŒฎ๐Ÿฏ๐Ÿฅ ๐Ÿฅข๐Ÿด๐Ÿฅ„๐Ÿฅ‚โ˜•๏ธ๐Ÿ˜€๐Ÿ˜ƒ๐Ÿ˜„๐Ÿคฃ๐Ÿ˜‚๐Ÿ˜…๐Ÿ˜†โ˜บ๏ธ๐Ÿ˜Š๐Ÿ˜๐Ÿ˜Œ ๐Ÿ˜˜๐Ÿ˜—๐Ÿ˜™๐Ÿ˜š๐Ÿ˜œ๐Ÿ˜๐Ÿ˜›๐Ÿ˜‹๐Ÿคจ๐Ÿง๐Ÿค“๐Ÿ˜’๐Ÿ˜๐Ÿคฉ๐Ÿคฉ๐Ÿ˜Ž๐Ÿ˜ž๐Ÿ˜”๐Ÿ˜–๐Ÿ˜ข๐Ÿ˜ฃโ˜น๏ธ๐Ÿ˜ฉ๐Ÿ™๐Ÿคฏ ๐Ÿ˜ฐ๐Ÿ˜“๐Ÿ˜ฆ๐Ÿ˜ฒ๐Ÿค’๐Ÿค•๐Ÿ‘ฟ๐Ÿ‘น๐Ÿ‘ฝโœŠ๐Ÿผ"

It leaves the other languages properly but some emojis are left.

9mm

9mm OP

I did find this guys ruby gem but I just wasted like an hour trying to convert this regex and when it finally worked it erased all the chinese characters, so obviously I got that wrong

https://github.com/guanting112/remove_emoji

mudasobwa

mudasobwa

Creator of Cure

There are many issues here. Both characters above are not in the range you specified in the first place.

โ–ถ to_charlist "๐Ÿ’ฐ" 
#โ‡’ [128176]
โ–ถ to_charlist "๐Ÿ’ฒ"
#โ‡’ [128178]
โ–ถ 0x1F600
#โ‡’ 128512

To make it work for the range with \u, just interpolate the literals (I voluntarily changed the starting value for the range to what it probably should be):

โ–ถ Regex.replace(~r/[#{"\u{1F000}"}-#{"\u{1F6FF}"}]/u, "๐Ÿ’ฐ Monies! ๐Ÿ’ฒ", "")
" Monies! "

\x will work out of the box with a proper range:

Regex.replace(~r/[\x{1F000}-\x{1F6FF}]/u, "๐Ÿ’ฐ Monies! ๐Ÿ’ฒ", "")
" Monies! "
kip

kip

ex_cldr Core Team

Yes, I see the same. Itโ€™s a bit surprising since according to some utility code I wrote they look to be So but re certainly doesnโ€™t agree:

iex> x
"๐Ÿคจ๐Ÿง๐Ÿค“๐Ÿคฉ"
iex> Cldr.Unicode.Category.category x 
[:So, :So, :So, :So]
iex> String.replace x, ~r/\p{So}/u, ""
"๐Ÿคจ๐Ÿง๐Ÿค“๐Ÿคฉ"
kip

kip

ex_cldr Core Team

Seems that emoji belong to the Common script so this appears to get closer - but it also deletes digits and punctuation.

iex> x = "abcdefghijklmnopqrstuvwxyz....0123456789 ไธๆฅต๏ผŒ็‰ฉ็‰‡้กžๆ›ธ่ปŠ่ฃก๏ผๅไปŠๆžœๅŠๆŽฅๅœ‹ๅ…ˆ้›„ ใƒ‹ใƒƒใƒใƒณใ€ใ€Œใƒ‹ใƒ›ใƒณใ€ไธกๆ–นไฝฟ็”จใ•ใ‚Œใ‚‹ไธญ ใซใฏๆ–‡์ค‘๊ตญ, ์ผ๋ณธ, ๋ฒ ํŠธ๋‚จ ๋“ฑ ํ•œ์ž ๋ฌธํ™”๊ถŒ์— ์†ํ•˜๋Š” ์•„์‹œ์•„ ์—ฌ๋Ÿฌ ๊ตญ๊ฐ€์—์„œ๋Š” ํ•œ๊ตญ์–ด็š„ๅทฎๅผ‚ๅค–๏ผŒ้€šๅธธ่ฎคไธบ่ฟ˜ๅญ˜ๅœจ่ฏๆฑ‡ไธŠ็š„ๅทฎๅผ‚ใ€‚ไพ‹ๅฆ‚็นไฝ“ไธญๆ–‡้‡Œๅคš็”จ็š„โ€œๅŽŸ ู„ู…ู†ุทู‚ุฉ ุงู„ุดุฑู‚ ุงู„ุฃูˆุณุท ู‡ูŠู„ูŠ: ุงู„ุชุญุฑูƒ ุถุฏ ุฅูŠุฑุงู† ุณูŠุจุฏุฃ ู…ู† ู…ุฌู„ุณ ุงู„ุฃู…ู†๐Ÿ“Œโ˜ฎ๏ธ๐Ÿ’Ÿ๐Ÿ”ฏโ˜ช๏ธใŠ—๏ธ๐Ÿˆต๐Ÿ†š๐Ÿ’ฏโ•๐Ÿ”ž๐Ÿšท๐Ÿ”ฐโ‰๏ธโš ๏ธ๐Ÿ’ค๐ŸŒ๐ŸŒ€โ–ถ๏ธ๐Ÿ” ๐Ÿ”ฃโ†”๏ธโ†ฉ๏ธ๐Ÿ‘โ€๐Ÿ—จ๐Ÿ—จ๐Ÿ—จ๐Ÿ—จ๐Ÿ—จ โ—ฝ๏ธ๐Ÿ”ฒ๐Ÿ‡ต๐Ÿ‡ฆ๐Ÿณ๏ธ๐Ÿณ๏ธโ€๐ŸŒˆ๐ŸŒˆ๐ŸŒˆ๐ŸŒˆ๐ŸŒˆ๐Ÿ‡น๐Ÿ‡ฒ๐Ÿ‡น๐Ÿ‡ท๐Ÿค›๐Ÿคœ๐Ÿผ๐Ÿ‘๐Ÿฝ๐Ÿ‘Œโ˜๐Ÿผ๐Ÿฅ๐Ÿฅฆ๐ŸŒถ๐ŸŒฝ๐ŸŽ ๐Ÿฒ๐Ÿ”๐Ÿฅž๐Ÿ๐Ÿ”๐Ÿ—๐ŸŒฎ๐Ÿฏ๐Ÿฅ ๐Ÿฅข๐Ÿด๐Ÿฅ„๐Ÿฅ‚โ˜•๏ธ๐Ÿ˜€๐Ÿ˜ƒ๐Ÿ˜„๐Ÿคฃ๐Ÿ˜‚๐Ÿ˜…๐Ÿ˜†โ˜บ๏ธ๐Ÿ˜Š๐Ÿ˜๐Ÿ˜Œ ๐Ÿ˜˜๐Ÿ˜—๐Ÿ˜™๐Ÿ˜š๐Ÿ˜œ๐Ÿ˜๐Ÿ˜›๐Ÿ˜‹๐Ÿคจ๐Ÿง๐Ÿค“๐Ÿ˜’๐Ÿ˜๐Ÿคฉ๐Ÿคฉ๐Ÿ˜Ž๐Ÿ˜ž๐Ÿ˜”๐Ÿ˜–๐Ÿ˜ข๐Ÿ˜ฃโ˜น๏ธ๐Ÿ˜ฉ๐Ÿ™๐Ÿคฏ ๐Ÿ˜ฐ๐Ÿ˜“๐Ÿ˜ฆ๐Ÿ˜ฒ๐Ÿค’๐Ÿค•๐Ÿ‘ฟ๐Ÿ‘น๐Ÿ‘ฝโœŠ๐Ÿผ"
"abcdefghijklmnopqrstuvwxyz....0123456789 ไธๆฅต๏ผŒ็‰ฉ็‰‡้กžๆ›ธ่ปŠ่ฃก๏ผๅไปŠๆžœๅŠๆŽฅๅœ‹ๅ…ˆ้›„ ใƒ‹ใƒƒใƒใƒณใ€ใ€Œใƒ‹ใƒ›ใƒณใ€ไธกๆ–นไฝฟ็”จใ•ใ‚Œใ‚‹ไธญ ใซใฏๆ–‡์ค‘๊ตญ, ์ผ๋ณธ, ๋ฒ ํŠธ๋‚จ ๋“ฑ ํ•œ์ž ๋ฌธํ™”๊ถŒ์— ์†ํ•˜๋Š” ์•„์‹œ์•„ ์—ฌ๋Ÿฌ ๊ตญ๊ฐ€์—์„œ๋Š” ํ•œ๊ตญ์–ด็š„ๅทฎๅผ‚ๅค–๏ผŒ้€šๅธธ่ฎคไธบ่ฟ˜ๅญ˜ๅœจ่ฏๆฑ‡ไธŠ็š„ๅทฎๅผ‚ใ€‚ไพ‹ๅฆ‚็นไฝ“ไธญๆ–‡้‡Œๅคš็”จ็š„โ€œๅŽŸ ู„ู…ู†ุทู‚ุฉ ุงู„ุดุฑู‚ ุงู„ุฃูˆุณุท ู‡ูŠู„ูŠ: ุงู„ุชุญุฑูƒ ุถุฏ ุฅูŠุฑุงู† ุณูŠุจุฏุฃ ู…ู† ู…ุฌู„ุณ ุงู„ุฃู…ู†๐Ÿ“Œโ˜ฎ๏ธ๐Ÿ’Ÿ๐Ÿ”ฏโ˜ช๏ธใŠ—๏ธ๐Ÿˆต๐Ÿ†š๐Ÿ’ฏโ•๐Ÿ”ž๐Ÿšท๐Ÿ”ฐโ‰๏ธโš ๏ธ๐Ÿ’ค๐ŸŒ๐ŸŒ€โ–ถ๏ธ๐Ÿ” ๐Ÿ”ฃโ†”๏ธโ†ฉ๏ธ๐Ÿ‘โ€๐Ÿ—จ๐Ÿ—จ๐Ÿ—จ๐Ÿ—จ๐Ÿ—จ โ—ฝ๏ธ๐Ÿ”ฒ๐Ÿ‡ต๐Ÿ‡ฆ๐Ÿณ๏ธ๐Ÿณ๏ธโ€๐ŸŒˆ๐ŸŒˆ๐ŸŒˆ๐ŸŒˆ๐ŸŒˆ๐Ÿ‡น๐Ÿ‡ฒ๐Ÿ‡น๐Ÿ‡ท๐Ÿค›๐Ÿคœ๐Ÿผ๐Ÿ‘๐Ÿฝ๐Ÿ‘Œโ˜๐Ÿผ๐Ÿฅ๐Ÿฅฆ๐ŸŒถ๐ŸŒฝ๐ŸŽ ๐Ÿฒ๐Ÿ”๐Ÿฅž๐Ÿ๐Ÿ”๐Ÿ—๐ŸŒฎ๐Ÿฏ๐Ÿฅ ๐Ÿฅข๐Ÿด๐Ÿฅ„๐Ÿฅ‚โ˜•๏ธ๐Ÿ˜€๐Ÿ˜ƒ๐Ÿ˜„๐Ÿคฃ๐Ÿ˜‚๐Ÿ˜…๐Ÿ˜†โ˜บ๏ธ๐Ÿ˜Š๐Ÿ˜๐Ÿ˜Œ ๐Ÿ˜˜๐Ÿ˜—๐Ÿ˜™๐Ÿ˜š๐Ÿ˜œ๐Ÿ˜๐Ÿ˜›๐Ÿ˜‹๐Ÿคจ๐Ÿง๐Ÿค“๐Ÿ˜’๐Ÿ˜๐Ÿคฉ๐Ÿคฉ๐Ÿ˜Ž๐Ÿ˜ž๐Ÿ˜”๐Ÿ˜–๐Ÿ˜ข๐Ÿ˜ฃโ˜น๏ธ๐Ÿ˜ฉ๐Ÿ™๐Ÿคฏ ๐Ÿ˜ฐ๐Ÿ˜“๐Ÿ˜ฆ๐Ÿ˜ฒ๐Ÿค’๐Ÿค•๐Ÿ‘ฟ๐Ÿ‘น๐Ÿ‘ฝโœŠ๐Ÿผ"
iex> String.replace x, ~r/\p{Common}/u, ""
"abcdefghijklmnopqrstuvwxyzไธๆฅต็‰ฉ็‰‡้กžๆ›ธ่ปŠ่ฃกๅไปŠๆžœๅŠๆŽฅๅœ‹ๅ…ˆ้›„ใƒ‹ใƒƒใƒใƒณใƒ‹ใƒ›ใƒณไธกๆ–นไฝฟ็”จใ•ใ‚Œใ‚‹ไธญใซใฏๆ–‡์ค‘๊ตญ์ผ๋ณธ๋ฒ ํŠธ๋‚จ๋“ฑํ•œ์ž๋ฌธํ™”๊ถŒ์—์†ํ•˜๋Š”์•„ ์‹œ์•„์—ฌ๋Ÿฌ๊ตญ๊ฐ€์—์„œ๋Š”ํ•œ๊ตญ์–ด็š„ๅทฎๅผ‚ๅค–้€šๅธธ่ฎคไธบ่ฟ˜ๅญ˜ๅœจ่ฏๆฑ‡ไธŠ็š„ๅทฎๅผ‚ไพ‹ๅฆ‚็นไฝ“ไธญๆ–‡้‡Œๅคš็”จ็š„ๅŽŸู„ู…ู†ุทู‚ุฉุงู„ุดุฑู‚ุงู„ุฃูˆุณุทู‡ูŠู„ูŠุงู„ุชุญุฑูƒุถุฏุฅูŠุฑุงู†ุณูŠุจุฏุฃู…ู†ู…ุฌู„ุณุงู„ุฃู…ู†๏ธ๏ธ๏ธ๏ธ๏ธ๏ธ๏ธ๏ธโ€๏ธ๏ธ๏ธโ€๏ธ๏ธ๏ธ" 
9mm

9mm OP

That is good but it removed tons of numbers and such, so Iโ€™m nervous about using that as I have no idea what all itโ€™s going to remove :confused:

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, Iโ€™ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
Iโ€™m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, Iโ€™ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
psy-q
Iโ€™m trying to set up Emacs with elixir-ls via lsp-mode and credo via Flycheck. This should mostly be preconfigured as Flycheck picks up c...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very ฮฑ version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, itโ€™s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rustโ€™s ratatui via Rustler NIFs. Build interactive terminal applicatio...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews