0

so I have a long string: "§aSomething, §bthat this §csomething else" and it's dynamic, I want to know how I can replace all of those "§a" or whatever the number is to nothing.

2 Answers2

1

Use regular expression

"§aSomething, §bthat this §csomething else".replace(/§./g,"")

. = Any single character

g = Global (search on entire string)

1

In case you want to increase the number of letters you can also use

var string = "§aSomething, §bthat this §csomething else"
string = string.replace(/[§][a-z]{1}/g, '');

where {1} represents the number of letters after §

Output:

Something, that this something else
Bharath M Shetty
  • 30,075
  • 6
  • 57
  • 108