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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:27:08+00:00 2026-06-03T08:27:08+00:00

I’m writing a script to go through a product database with poorly, inconsistently formatted

  • 0

I’m writing a script to go through a product database with poorly, inconsistently formatted product descriptions to make its HTML uniform. One problem I’m having is capturing and replacing lines of code formatted the same way. For example, I’d like to replace all their

• item 1
• item 2
• item 3

with

<ul>
  <li>item 1</li>
  <li>item 3</li>
  <li>item 2</li>
</ul>

Replacing each &bull; line with a <li>content</li> line is easy enough, but I can’t for the life of me figure out the regex to get before and after the list. My though is to capture everything starting with &bull; until there is a newline that does not start with &bull;. Here’s my latest try (python):

In  : p = re.compile(
        r'&bull;.*(?!^&bull;)'
      )

In  : p.findall(text, re.MULTILINE, re.DOTALL)
Out : []

In  : p.findall(text, re.MULTILINE)
Out : ['&bull; item 1', '&bull; item 2', '&bull; item 3']

In  : p.findall(text, re.DOTALL)
Out : ['&bull; item 1', '&bull; item 2', '&bull; item 3']

In  : p.findall(text)
Out : ['&bull; item 1', '&bull; item 2', '&bull; item 3']

Any ideas on how to capture something like ['&bull; item 1\n&bull; item 2\n&bull; item 3']?

  • 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-03T08:27:09+00:00Added an answer on June 3, 2026 at 8:27 am

    Here’s a non-regex based solution:

    with open('/tmp/example.txt') as f:
      lines_in = f.readlines()
    
    inside_block = False
    lines_out = []
    
    for line in lines_in:
      if line.startswith('&bull; '):
        if not inside_block:
          lines_out.append('<ul>\n')
          inside_block = True
        lines_out.append('<li>{}</li>\n'.format(line.strip().replace('&bull; ','')))
      else:
        if inside_block:
          lines_out.append('</ul>\n')
          inside_block = False
        lines_out.append(line)
    
    print ''.join(lines_in)
    print '-'*78
    print ''.join(lines_out)
    

    Test run:

    [~/Desktop]
    |7>run /tmp/spam.py
    spam
    &bull; item 1
    &bull; item 2
    &bull; item 3
    and eggs
    
    ------------------------------------------------------------------------------
    spam
    <ul>
    <li>item 1</li>
    <li>item 2</li>
    <li>item 3</li>
    </ul>
    and eggs
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
i got an object with contents of html markup in it, for example: string
I am writing an app with both english and french support. The app requests
I have thousands of HTML files to process using Groovy/Java and I need to
I have a reasonable size flat file database of text documents mostly saved in

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.