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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:26:20+00:00 2026-06-15T20:26:20+00:00

I am writing a python library that takes a paragrah that consists of different

  • 0

I am writing a python library that takes a paragrah that consists of different types of hours format. Paragraph is actually taken from different restaurant sites, they have hours of operation in various formats for each site. So, I decided to write a library that takes any format of (eg: M-Fri 10am – 12pm, M, Tue, Wed 00:00-18:00 etc.). My decision is to write different set of RegEx that takes a string and proceeds if it matches any of my pattern.

I have choosen RegEx pattern matching because, instead of writing own logics for every pattern and replacing just using str.replace may takes a lot of time. But I stuck in regex since I am new to it. So any of you can suggest me how can I do the following task?

As a first step I would like to shorten all the weekday formats to 3 letter shorten week days as below.
Example:
“Monday 09:00 AM – 5:00 PM, Tuesday 09:00 AM – 5:00 PM, Wednesday 09:00 AM – 5:00 PM, Thursday 09:00 AM – 5:00 PM, Friday 09:00 AM – 5:00 PM, Saturday Closed, Sunday Closed“

Output should be
“Mon 09:00 AM – 5:00 PM, Tue 09:00 AM – 5:00 PM, Wed 09:00 AM – 5:00 PM, Thu 09:00 AM – 5:00 PM, Fri 09:00 AM – 5:00 PM, Sat Closed, Sun Closed”

Thanks.

  • 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-15T20:26:22+00:00Added an answer on June 15, 2026 at 8:26 pm

    seems like a simple str.replace should work here:

    new_paragraph = paragraph.replace('Monday','Mon')
    

    You can even use the calendar module to make this a little easier:

    import calendar
    
    for day,abbr in zip(calendar.day_name,calendar.day_abbr):
        paragraph = paragraph.replace(day,abbr)
    

    for really big paragraphs, it might be worthwhile to switch over to regex:

    import re
    import calendar
    
    regex = re.compile('|'.join(calendar.day_name))
    sub_dict = dict(zip(calendar.day_name,calendar.day_abbr))
    new_paragraph = regex.sub(lambda match: sub_dict[match.group(0)],paragraph)
    

    Of course, with calendar, the abbreviations/etc are locale dependent (but maybe that’s desirable anyway)

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

Sidebar

Related Questions

I'm writing a Python application that takes a command as an argument, for example:
I have some python code that: Takes a BLOB from a database which is
I'm writing a python library that has a per-user configuration file that can be
I am writing some Python code that uses a library to communicate with an
I'm writing some unit tests for a Python library and would like certain warnings
I'm writing a Python wrapper for a C++ library, and I'm getting a really
I am writing python script which gets links from website. But when I tried
I'm using a python library. I don't know about the indentation that the writer
Good morning, I am currently writing a python library. At the moment, modules and
I am writing a Python utility that needs to parse a large, regularly-updated CSV

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.