0

I can't use methods like Replace so I need a Regex statement that will replace underscores and add a space instead.

I thought that /([^_])/ would at least return the string without the underscore but it only returns certain strings with the first character.

41686d6564
  • 15,043
  • 11
  • 32
  • 63

1 Answers1

1

Sample String x is:

val x = "this_string_contains_Underscore_characters."

Use the below command on this string x:

x.split("_").mkString(" ")

or Use replaceAll:

x.replaceAll("_", " ")

In Scala REPL:

scala> val x = "this_string_contains_Underscore_characters."
x: String = this_string_contains_Underscore_characters.

scala> x.split("_").mkString(" ")
res28: String = this string contains Underscore characters.

scala> x.replaceAll("_", " ")
res50: String = this string contains Underscore characters.
RAGHHURAAMM
  • 1,113
  • 4
  • 14
  • I can't use things like "split" and "replace" in Grafana. I need a regex statement that will do exactly what you did for javascript and scala. I'm trying it on this site https://regexr.com/ – user9864738 Aug 06 '18 at 14:26