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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T21:21:40+00:00 2026-05-23T21:21:40+00:00

I need to write a regex which matches strings representing comma separated days of

  • 0

I need to write a regex which matches strings representing comma separated days of week, like:

"Sun,Mon,Tue,Wed,Thu,Fri,Sat"

Each day can appear in the string at most once. The order of days is important.

So far I have tried the following patterns:

1) (Sun,|Mon,|Tue,|Wed,|Thu,|Fri,|Sat,)*(Sun|Mon|Tue|Wed|Thu|Fri|Sat)

This one is very bad: allows multiple presence of days, also doesn’t watch over the days order.

2) (Sun)?([,^]Mon)?([,^]Tue)?([,^]Wed)?([,^]Thu)?([,^]Fri)?([,^]Sat)?

This is the best I got so far. The only problem here is that it matches strings starting with comma, e.g. ,Mon,Tue,Fri. My question is how to filter out the comma starting string matching this pattern.

Thanks in advance.

  • 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-05-23T21:21:40+00:00Added an answer on May 23, 2026 at 9:21 pm

    Agreed that regex is possibly not the best option. However, if the only problem with your current version is that it matches strings beginning with a comma, you could just bung a check for a starting comma at the beginning of the regex:

    (?!,)(Sun)?([,^]Mon)?([,^]Tue)?([,^]Wed)?([,^]Thu)?([,^]Fri)?([,^]Sat)?
    

    However, I don’t think [,^] does what you think it does – in the regex flavours I’m familiar with, ^ inside square brackets matches a literal ^ when it’s not the first character in the list – it doesn’t match the beginning of the string. You could replace it with (^|,):

    (?!,)(Sun)?((^|,)Mon)?((^|,)Tue)?((^|,)Wed)?((^|,)Thu)?((^|,)Fri)?((^|,)Sat)?
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to write a small regex which should match the occurrences of literal
I need to write a regex which will match URLs that do not have
I want to write a conditional regex which matches 1 of 2 patterns. To
I need to write regex which I will use for asp.net routing constraint which
I need write an update statement that used multiple tables to determine which rows
I need to write a Java Comparator class that compares Strings, however with one
In my Python application, I need to write a regular expression that matches a
I have a file which has text like this: #1#14#ADEADE#CAH0F#0#0..... I need to create
I would like a Perl regex that matches any contiguous subset of the string
I need to write a program used internally where different users will have different

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.