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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:00:49+00:00 2026-06-05T09:00:49+00:00

this is some kind of variable content in javascript: <meta charset=utf-8> <title>Some Meep meta,

  • 0

this is some kind of variable content in javascript:

    <meta charset="utf-8">

    <title>Some Meep meta, awesome</title>




    <-- some comment here -->
    <meta name="someMeta, yay" content="meep">

</head>

I want to reduce the multi line breaks (unknown number) to a single line break while the rest of the formatting is still maintained. This should be done in javascript with a regex.

I have problems with the tabulator or to keep the format.

  • 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-05T09:00:50+00:00Added an answer on June 5, 2026 at 9:00 am

    Try this:

    text.replace(/\n\s*\n/g, '\n');
    

    This basically looks for two line breaks with only whitespace in between. And then it replaces those by a single line break. Due to the global flag g, this is repeated for every possible match.

    edit:

    is it possibile to leave a double line break instead of a single

    Sure, simplest way would be to just look for three line breaks and replace them by two:

    text.replace(/\n\s*\n\s*\n/g, '\n\n');
    

    If you want to maintain the whitespace on one of the lines (for whatever reason), you could also do it like this:

    text.replace(/(\n\s*?\n)\s*\n/, '$1');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I implemented some app that can start Play Store. This is some kind of
How do I simplify this templated vector initializer loop using lambdas or some kind
What does this bit of code represent? I know it's some kind of if
I am going crazy now. Googled this, thought some kind of IDE bug. Maybe
Possible Duplicate: Is there a CSS parent selector? Is there some kind of .this
This is kind of embarrassing but I cannot for some reason get his CSS
I there a way to compare some string in php with this kind of
I'm doing things considered horrible by some lately, but I personally enjoy this kind
I want to have URLs like this: some-company-name-deal-id-6.htm So the rewrite rule should ignore
because of some problems with joomla in-content javascript I have to give all my

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.