Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8911261
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:53:53+00:00 2026-06-15T03:53:53+00:00

I am struggling to concatenate a message with two texts into a single text

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T03:53:54+00:00Added an answer on June 15, 2026 at 3:53 am

    This is really not an ideal problem for regexes, but okay:

    val Part = """"([^"]*)"(.*$)""".r    // Quotes, non quotes, quotes, then the rest
    val Plus = """\s*\+\s*(.*)""".r      // Plus with optional spaces, then the rest
    
    def parts(s: String, found: List[String] = Nil): String = s match {
      case Part(p,rest) => rest match {
        case "" => (p :: found).map(_.filter(c => !c.isWhitespace)).reverse.mkString(" ")
        case Plus(more) => parts(more, p :: found)
        case x => throw new IllegalArgumentException(s"$p :$x:")
      }
      case x => throw new IllegalArgumentException(s"|$x|")
    }
    

    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.)

    scala> parts(""""part1 "+" part2"""")
    res1: String = part1 part2
    
    scala> parts(""""part1 "   + " part2"""")
    res2: String = part1 part2
    
    scala> parts(""""part 1 "+    " part2"""")
    res3: String = part1 part2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im struggling with Valumx exellent Fileupload. Ive been using it for a couple of
been struggling with an issue now for a day or two. I have an
Struggling with onchange for JQuery Datetime plugin: http://plugins.jquery.com/project/datetime I am using the following code.
still struggling with regex :) i have this code: $link = '/\bhttp:\/\/.+\..+[\/\w]?\b/i'; $match =
Struggling a bit on this... I'm using crontab for a lot of todo list
Struggling to parse this JSON response from http://api.twitter.com/1/trends/current.json using foreach ($json_output->trends[0] as $trend )
Struggling with an install of GAE-Patch and using my stylesheets. My settings.py has the
In struggling with a solution to this problem I've run into another, related issue:
Im struggling to create a tabbing technique using jquery so that the user can
Struggling to understand why my validator chain is showing the incorrect message for the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.