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 8273101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:21:47+00:00 2026-06-08T07:21:47+00:00

I have stream of data coming from different feeds which I need to clean

  • 0

I have stream of data coming from different feeds which I need to clean up.

Data is in specific format and if some sentence spans through multiple lines it is separated using “\”(backslash), which I want to remove. \ is also present in other part of text for escaping quotes etc and I don’t want to remove these backslashes. So eventually I want to remove “\\n”.

I have tried following regex for removing \ and \n but it didn’t work :

singleLine.replaceAll("(\\\\n|\\\\r)", "");

I am not sure what regex would work in this case.

  • 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-08T07:21:49+00:00Added an answer on June 8, 2026 at 7:21 am

    Regex isn’t really necessary for this; If I were you, I would use…

    singleLine=singleLine.replace("\\\\n", "");
    

    Many people think the replace method only replaces one, but in fact the only difference is that replaceAll uses regex, while replace simply replaces exact matches of the String.

    If you do want to use regex though, I believe you have to do \\\\\\\\ (you have to ‘nullify’ the escape character in Java, and in regex, so x4, not just x2)

    Explaining this some more

    The only other issue is in your example, you never set singeLine equal to anything; I’m not sure if you hid that, or missed that.

    Edit:
    Explaining the reasoning for \\\\\\\\ some more, Java requires that you do “\\” to represent one \. Regex also has a use for the \ character, and requires you do the same again for it. If you just “\\” in Java, the regex parser essentially receives “\”, it’s escape character for certain things. You need to give the regex parser two of them, to escape it, so in Java, you need to do “\\\\” just to represent a match for a single “\”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stream of data coming in from an external source which I
I have a Stream of audio data coming from my mic for which I
I have a stream of data coming in over the serial line from an
I have a video stream coming in from the Kinect. It's data is packed
I have a stream of xml being returned from a webservice which is coming
I have written an application which triggers an IP Camera to stream it's data
I have a DLL which outpus data to a stream. But it adds a
So I am trying to retrieve data from an XML stream coming from a
I have data coming in from a machine (via pexpect) and I parse it
I have a stream of data which consists of 64-bit IEEE standard 754 floating

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.