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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:39:38+00:00 2026-06-18T09:39:38+00:00

I am writing a program to validate and correct a given date as a

  • 0

I am writing a program to validate and correct a given date as a string. Lets take 04121987 as the date in the format ddmmyyyy. A regular expression for such a date:

(0[1-9]|[12][0-9]|3[01])(0[1-9]|1[012])(19\d\d|20\d\d)

If I match my string with the regular expression it works well. In Python:

>>> regex = re.compile(r'(0[1-9]|[12][0-9]|3[01])(0[1-9]|1[012])(19\d\d|20\d\d)')
>>> regex.findall('04121987')
[('04', '12', '1987')]

If I have a string 04721987 one can clearly see 72 is not a valid month and thus the string will not match the regex.

>>> regex.findall('04721987')
[]

What I would like to find out is the character which causes the regex to fail and its position. In this case it is 7. How could I do this in Python?

  • 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-18T09:39:39+00:00Added an answer on June 18, 2026 at 9:39 am

    I believe what you want isn’t possible, because _sre module is implemented in C ;(.

    You could try using this package instead (by monkey patching sre_compile, modifying the path and importing your new _srefirst, etc.) but I don’t think it worths it. It is an implementation of the _sre package fully written in Python, so you’ll be able to see the source code, edit it, and do something right when the next character doesn’t match.

    You could do a similar thing by either:

    • Splitting the date string in 3 (day, month and year) and matching the regular expressions independently
    • validating the date time using another way that doesn’t involve regex

    Perhaps you don’t obtain the exact digit where the error is, but I don’t think it makes too much sense in this scenario, as long as you tell the user what is wrong (day, month or year).

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

Sidebar

Related Questions

HI , I am writing a java program to validate email addresses. This program
I'm writing a program to validate credit card numbers and I have to use
Im writing a program for homework where I need to validate user input and
I am writing program that does alot of table lookups. As such, I was
I'm writing program in C# for converting between model formats. The model format has
I am writing a program to validate a CSV file. The limitations on the
Im writing a program that should read input via stdin, so I have the
I'm writing a program that handles DBs and writes any changes into ListView for
I am currently writing a program using Weka that builds a model (using one
I was writing a program to concatenate two arrays in C. I am allocating

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.