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

katta
I having some trouble figuring out if I have set myself too strict of standards for my production server. Currently I can handle 75% of r...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
achenet
Hello, Iโ€™m trying to build a basic Phoenix web-app, and Iโ€™d like to use Tailwind. However, when I launch mix phx.server, I get an error...
New
kpanic
Hi everyone, I am toying with the idea of building a โ€œmatch makerโ€ for giving personal help to people that wants to start coding. I sta...
New
asweet-confluent
I recently noticed that Elixirโ€™s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
Cxx-mlr
Iโ€™m working on a small exercise involving update_in/3, and I came up with this solution: data = %{ name: "Periodic Table", category:...
New
ChrisAmelia
Iโ€™ve got trouble wrapping my head around the order in which functions are called in this snippet (from Phoenixโ€™s authentication): toke...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 โ€” Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, Iโ€™m Jesse and Iโ€™m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
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
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! Weโ€™ve published a press release detai...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews