2

I have a string like this: bat★☆ ⛱ ✨‍♂️⛷❤️֎۩ᴥ★ Lôa Créole♥ Now, I need to replace all of emoji symbol to empty string but I also need to remain ô and é. I checked from internet to use like this:

regexp_replace(df("word"), """[^ 'a-zA-Z0-9,.?!]""","")

But this method also covered ô and é. Would you please help to guide how to exclude the ô and é, only emoji symbol

scala>     val df = Seq(
     |       (8, "bat★☆  ⛱ ✨♂⛷❤֎۩ᴥ★ Lôa Créole♥"),
     |       (64, "bb")
     |     ).toDF("number", "word")
df: org.apache.spark.sql.DataFrame = [number: int, word: string]

scala> df.select($"number", $"word", regexp_replace(df("word"), """[^ 'a-zA-Z0-9,.?!]""","").alias("word_revised")).show(false)
+------+------------------------------------------------+---------------+
|number|word                                            |word_revised   |
+------+------------------------------------------------+---------------+
|8     |bat★☆  ⛱ ✨‍♂️⛷❤️֎۩ᴥ★ Lôa Créole♥|bat    La Crole|
|64    |bb                                              |bb             |
+------+------------------------------------------------+---------------+

Tom Tang
  • 169
  • 4
  • 12
  • 1
    this question has already been answered here https://stackoverflow.com/questions/20690499/concrete-javascript-regular-expression-for-accented-characters-diacritics – randbw Feb 04 '22 at 08:59

0 Answers0