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

The Archive Base Latest Questions

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

I would like to split a paragraph with javascript if inside of the paragraph

  • 0

I would like to split a paragraph with javascript if inside of the paragraph I have <br /> followed by newline and by a digit.

Here is the example of the paragraph:

aaaaaa aaaaa aaaaa aaaaa aaaa <br />
1   bbbb bbbbb bbbbb bbbb bbb <br />
2   cccc ccccc ccccc cccc ccc <br />
*   dddd ddddd ddddd dddd ddd <br />

And I would like to have an array with 3 elements inside:

1.  aaaaaa aaaaa aaaaa aaaaa aaaa <br />
2.  1   bbbb bbbbb bbbbb bbbb bbb <br />
3.  2   cccc ccccc ccccc cccc ccc <br />
    *   dddd ddddd ddddd dddd ddd <br />

I have tried this:

<br \/>\d

But this not worked because of the newline I guess.

Thank you very much for your help.

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

    Assuming the string is stored in a variable called str, the following should work:

    str.split(/<br \/>$[\s\S]^(?=\d+)/m)
    

    I have used:

    • Multi-line mode (/m), to allow the $ to match the end of one line, and the ^ to match the start of the next.
    • A javascript regex trick to match any character, including new lines: [\s\S], as detailed here.
    • A positive lookahead, to make sure the thing following the new line is a digit: (?=\d+). It is not included in the match, though, so the digits are not removed from the string.

    EDIT: This will remove the <br />s from all but the last element in the list. Since I cannot think of a better way right now, you could just re-add them using something like:

    var parts = str.split(/<br \/>$[\s\S]^(?=\d+)/m);
    var final = [];
    for (var i = 0; i < parts.length - 1; i++) {
        final.push(parts[i] + '<br />');
    }
    final.push(parts[parts.length - 1]);
    

    Not ideal, but seems to work for me.

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

Sidebar

Related Questions

I have a huge text file that I would like to split into multiple
I have a dataframe with one column that I would like to split into
I have a string a and I would like to split it in half
Suppose I have a string of 123456789 . I would like to split this
I have some data represented in a 1300x1341 matrix. I would like to split
i would like to split a text (using a regex) to a dot followed
I have an array I would like to split in half. So I can
I have the following string that I would like to split on the \xA7
I have a really long objective c function definition, and would like to split
I would like to split a string into fixed-length ( N , for example)

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.