I am struggling to concatenate a message with two texts into a single text using regex in scala
original message = "part1 "+" part2"
original message = "part1 " + " part2"
original message = "part 1 "+ " part2"
concatenated message = "part1 part2"
What I am using is this code below (to replace atleast the + sign with null)
val line:String = """"text1"+"text2"""" //My original String which is "text1"+"text2"
val temp_line:String = line.replaceAll("\\+","")
println(temp_line)
It works fine and results “text1″”text2”. Is there a way to get the output “text1 text2” using regex?
Please help. Thanks in advance
This is really not an ideal problem for regexes, but okay:
This just takes the input string apart piece by piece; you can add printlns if you want to see how it works. (Note that
+is a special character in regex, so you need to escape it to match it.)