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

  • Home
  • SEARCH
  • 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 8459915
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:27:39+00:00 2026-06-10T13:27:39+00:00

I have a form with: <textarea name=test> Assuming the user inputs the following text:

  • 0

I have a form with:

<textarea name="test">

Assuming the user inputs the following text:

This is the first paragraph
It has two lines

This is the second paragraph

I would like to split this text into a list [“This is the first paragraph\nIt has two lines”, “This is the second paragraph”]

I thought this would work:

temp = self.request.get("test")
list = re.split(r'\n\n', temp)

But it does not. However,

temp = self.request.get("test")
list = re.split(r'\n', temp)

yields the following list: [“This is the first line”, “”, “This is the second line”]

What am I missing?

ALSO:

Assuming there could be either one or two empty lines between the to texts, would this make sense?

temp = self.request.get("test")
list = re.split(r'(\n){2,3}', temp)

SOLUTION:

With the help below,

I’ve found out that the following code works in my case:

temp = self.request.get("test")
list = [l for l in temp.split('\r\n\r\n') if l.split()]

I think the line-breaking might depend on what system the input comes from, so it might not be the perfect solution.

  • 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-10T13:27:41+00:00Added an answer on June 10, 2026 at 1:27 pm

    I think re module might be overkill. Just split the content by \n and remove the empty strings.

    >>> s = """This is the text
    ... 
    ... I am interested in splitting,
    ... 
    ... 
    ... but I want to remove blank lines!"""
    >>> lines = [l for l in s.split("\n") if l]
    >>> lines
    ['This is the text', 'I am interested in splitting,', 'but I want to remove blank lines!']
    

    The string.split also appears to be about twice as fast.

    > python -m timeit -s 's = "This is the text\n\nthat I want to split\n\n\nand remove empty lines"; import re;' '[l for l in re.split(r"\n", s) if l]'   
    100000 loops, best of 3: 2.84 usec per loop
    
    > python -m timeit -s 's = "This is the text\n\nthat I want to split\n\n\nand remove empty lines"' '[l for l in s.split("\n") if l]'                    
    1000000 loops, best of 3: 1.08 usec per loop
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this form: <form action=contact.php method=post id=contactform> <ol> <li> <label for=name>First Name *
I have this form: <form name=commentform id=commentform action=comment.php method=post enctype=multipart/form-data> Your Name: <textarea maxlength=60
I have a form that embeds another form: <form> <input type=text name=main[name]> <textarea name=main[body]></textarea>
I have a comment form with a textarea, input text and input radio. first,
I have this form: <form name=form method=post> <div> <p> Problem Name: <input type=text size=20
I have a form for user to input some feedbacks, and this form has
I have a form with different html input fields... 1) <input type=text> 2) <textarea></textarea>
I have created a form <form name=form1 method=post> <textarea rows=5 cols=20 name=ta1></textarea> <input type=submit
I have a form with two fields with the name attribute of 'photo_title' and
I have this form <form action= method=post enctype=multipart/form-data name=form1 id=form1> <tr> <td width=32% valign=top>&nbsp;&nbsp;&nbsp;<strong

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.