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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:40:08+00:00 2026-06-15T15:40:08+00:00

I have been working with regex the entire day to parse a complicated string

  • 0

I have been working with regex the entire day to parse a complicated string into meaningfull data. I’ve nailed almost everything, but am left with this last problem:

I’m parsing a list of strings that represents a schedule. Every day is a seperate item in the list. Some days have multiple appointments on one day, like this line:

Tuesday 10/13/2011 SHIFT 00:00-08:00 Description of appointment DAYOFF 08:00-17:30 08:00-12:30 12:30-13:00 13:00-17:30 Description of appointment NIGHT 17:30-24:00 Description of appointment

I want this string to split into three lines based on the shift, but while maintaining the day and date. What all shifts have in common is that they consist of letters in caps, so [A-Z].

Expected output would be:

Tuesday 10/13/2011 SHIFT 00:00-08:00 Description of appointment
Tuesday 10/13/2011 DAYOFF 08:00-17:30 08:00-12:30 12:30-13:00 13:00-17:30 Description
Tuesday 10/13/2011 NIGHT 17:30-24:00 Description of appointment

I can’t simply scan for all possible shifts, because they are unkown, the only thing that is for sure is that they are in all caps. Therefore I need to use regex.

I thought of a structure like this (regexmatch = a shift ([A-Z]{5,})):

placeholder = []
for day in schedule:
    newLine = []
    if day.count(regexmatch) > 1:
        newline.append(day[:2])       #To include day and date
        i = 2
        for i < len(day):
            if day[i] == regexmatch:
                placeholder.append(newLine)
                newLine = []
                newLine.append(day[:2])
                newLine.append(day[i])
            else:
                newLine.append(day[i])
        i += 1
    placeholder.append(newLine)

I hope this makes sense and someone can help me implement the regexmatch into this, or maybe take an entirely different route.

  • 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-15T15:40:09+00:00Added an answer on June 15, 2026 at 3:40 pm

    I’d organize the code to generate the appointments (instead of repeatedly appending to a list):

    import re
    day_re = re.compile(r'((?:Mon|Tues|Wednes|Thurs|Fri|Sat|Sun)day \d{2}/\d{2}/\d{4}) (.*)')
    shift_re = re.compile(r'([A-Z]{5,} [^A-Z]*(?:[A-Z]{1,4}[^A-Z]+)*)')
    
    def appointments(lines):
        """
        Given iterator `lines` containing one or more appointments per day,
        generate individual appointments.
        """
        for line in lines:
            day, remainder = day_re.match(line).groups()
            shifts = shift_re.findall(remainder)
            if shifts:
                for shift in shifts:
                    yield '{} {}'.format(day, shift.strip())
            else:
                yield '{} {}'.format(day, remainder.strip())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on my date regular expression all day... I want a
I have a code that has been working for almost 4 years (since boost
I have a Regex in AS3. Until now it's been working, but now I
I have been working on this regex: {link=([^|{}]+)\||([^|{}]+)\||([^|{}]+)} I wish to capture any non-pipe
I've been working on this RegEx for the past day or so and I
Have been working on this question for a couple hours and have come close
I have been working with SQL Server as a Developer a while. One thing
I have been working on a large java application. It is quite parallel, and
I have been working on this app for at least 3-4 months and just
I have been working on a project in C# (.net4). Project pretty much allows

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.