Remove any Emoji from Text

Hi there,
I'm trying to use the search and replace tool to remove any and all emoji from my text. With numbers I can easily use something like "[0-9]" to work with a range of numbers, is there something similar for emoji?
Thank you!

You might try searching for the regular expression [^\w\d\s[[:punct:]]], which should find anything that is neither a letter, digit, space, or punctuation, and replacing it with nothing.


1 Like

That's perfect! Thank you so much :grin:


hey sorry to reopen but how would you do the same and just remove the emoji, so not replacing it with nothing. As that then leaves a space where that emoji was, say I just want to remove the emoji fully

No problem to reopen. However, I think you must have unwittingly typed a space in the replace field, because replacing the emoji with nothing shouldn't leave a space where that emoji was:


I don't write anything in the replace field so unsure why I'm getting this whitespace. Attached I tried to replicate yours, and still having it should incorrectly. Could you perhaps share the macros so I can direct import it?TEST.kmmacros (1.8 KB)

Aha, I see what the issue is now. The problem is that you happened to be using an emoji that included a nonspacing mark character, which caused the preceding space character to look like one giant space once the emoji was gone. Though they look identical to us, this version of the emoji is only one character:


while this one, which you were using in your test macro, is actually two:


If you use the version that's only one character, you can see that your macro was actually working fine:


If you want to account for this nonspacing mark character in the future, you can use this modified regex, which accounts for that character and deletes it as well:


I started using KM about 2 decades ago, but I only recently started playing with it again, after it lay dormant in my App folder for too many years. I'm just now [slowly] get the hang of it again.

I recently had a situation in which I needed [wanted] to remove emojis that were embedded within the filenames of almost 700 mp4 video files. Initially unable to find a solution, I manually modified every single file. (Duh!) Then it occurred to me that this would be a good reason to revive Keyboard Maestro.

After considerable searching, I found and tried your regex [both the original and modified versions]. While it almost worked, the process continually left one null character [space ?] in its place, just preceding the file extension.

Eventually, I added a second regex to handle the issue. The second regex was...

^[ \t]+|[ \t]+$

The procedure now works like magic! Thanks so much for the kick in the butt!


Remove Emojis [incl. spaces] from selected files.kmmacros (5.3 KB)

1 Like

NOTE: It just occurred to me that the characters I couldn't remove were TABs. I wasn't even aware that it was possible to embed a TAB within a filename!