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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:30:16+00:00 2026-06-14T00:30:16+00:00

My problem here is that i want a Character remove in some parts of

  • 0

My problem here is that i want a Character remove in some parts of a String but I do not know how to restrict the removing.

Example:

A computer is a general purpose device that can be\n
programmed to carry out a finite set of\n 
millions to billions of times more capable.\n
\n
In this era mechanical analog computers were used\n
for military applications.\n
1.1 Limited-function early computers\n
1.2 First general-purpose computers\n
1.3 Stored-program architecture\n
1.4 Semiconductors and\n

this here example is the content of my string, what i want to happen is to remove the \n of lines 1 and 2 above but not to remove the \n in line 5 onwards. How do i remove the \n without removing the other \n?. My Goal here is to make the string a paragraph without \n after line. like the example the first 3 lines can be a paragraph and the next lines are in bullet form(example). what i am saying is that I do not want to remove \n in bulleted characters.

The real contents of the string is dynamic.

I have tried using String.replaceAll("\n", " ") well clearly that would not work it will remove all the \n i have thought of using Regex to determine what is Alphanumberic but it would remove some letters after \n

  • 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-14T00:30:18+00:00Added an answer on June 14, 2026 at 12:30 am

    Try using this regex: –

    str = str.replaceAll("(.+)(?<!\\.)\n(?!\\d)", "$1 ");
    System.out.println(str);
    

    This will replace your \n if it is not preceded by a dot - termination of a paragraph, and it is not followed by a digit, for when it is followed by a bulleted point. (like, your \n in first bullet point is followed by a 1.2. So, it will not be replaced.).

    • (.+) at the start, ensures that you are not replacing a blank line.

    This will work for the string you have shown.

    Explanation: –

    • (.+) -> A capture group, capturing anything, occurring at least once.

    • (?<!\\.) -> This is called negative-look-behind. It matches the string following it, only if that string is not preceded by a dot(.) given in the negative-look-behind pattern.
      For e.g.: – You don’t need to replace \n after the line: – millions to billions of times more capable.\n.

    • (?!\\d) -> This is called negative -look-ahead. It matches string behind it, only if that string is not followed by a digit (\\d) given in the negative-look-ahead pattern.
      For e.g.: – In your bulleted points, computers\n is followed by 1.2. where 1 is a digit. So, you don’t want to replace that \n.

    • Now, $1 and $2 represent the groups captured in the pattern match. Since you just want to replace "\n". So, we took the remaining pattern match as it is, while replacing "\n" with a space.

    So, $1 is representation for 1st group – (.+)

    Note, look-ahead and look-behind regexes are non-capturing groups.

    For More Details, follow these links: –

    • http://docs.oracle.com/javase/tutorial/essential/regex/

    • http://docs.oracle.com/javase/tutorial/essential/regex/quant.html

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

Sidebar

Related Questions

date here my problem: String datetime = 2012-03-24 23:20:51; I know that that string
Updated Problem solved, I have some design problem here. The directory looks like that:
So here's my problem: I've created a custom AVCaptureSession that takes pictures. I'm not
I hav especific need of removing word from string, But I am having problem
I need help with a character encoding problem that I want to sort once
Here's my problem, I have a variable wrongly encoded that I want to fix.
Here is my situation: re.sub(r'([^\\])', r'\1[\W\1]*', string) It is straight forward that I want
I have a problem here that requires to design a data structure that takes
I built a linear layout inside of a dialog , the problem here that
My problem in here ( probably ) is that $db->fetch_array won't show all 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.