Scala replace one text for another text with special chars included

i need a function to replace one text per another one, currently this is the code i am using, but it's not really working, or at least instead of replacing, removing the text and leave it empty, this is the code:

Thanks for your time, appreciated

def replaceIcons(message: String) = {
    message.replaceAll("[|TInterfaceiconsInv_Misc_Tournaments_banner_Human.png:13,8:14:0,9:-2,8|t]:", "[https://cdn.discordapp.com/emojis/511683443231424532.png?v=1]:")
  }

This is the message i want to replace i.postimg.cc/zDHwfXHX/ser.png

The expected output is this one: i.postimg.cc/k4mCt5X3/serr.png

Example message to replace:

[global] [Zerobalas]: [|TInterfaceiconsInv_Misc_Tournaments_banner_Human.png:13,8:14:0,9:-2,8|t]: asd

Example output expected:

[global] [Zerobalas]: [https://cdn.discordapp.com/emojis/511683443231424532.png?v=1]: asd

Upvotes: 0

Views: 60

Answers (1)

Pedro Correia Luís
Pedro Correia Luís

Reputation: 1095

Try this:


def replaceIcons(message: String) = {
    message.replace("[|TInterfaceiconsInv_Misc_Tournaments_banner_Human.png:13,8:14:0,9:-2,8|t]:", "[https://cdn.discordapp.com/emojis/511683443231424532.png?v=1]:")
  }

  println(replaceIcons("[global] [Zerobalas]: [|TInterfaceiconsInv_Misc_Tournaments_banner_Human.png:13,8:14:0,9:-2,8|t]: asd"))

Upvotes: 1

Related Questions