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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T02:59:22+00:00 2026-06-12T02:59:22+00:00

I am trying to scan some documents to find dates for a classification problem.

  • 0

I am trying to scan some documents to find dates for a classification problem. After reading around here and some other places I have constructed the following regular expression

months='['+'|'.join(calendar.month_abbr[1:])+'|'+'|'.join(calendar.month_name[1:])+']'
techPart='+\\.*\\s*\\d{1,2}[,]?[\\s*][1|2]\\d{3}'
dateExpr=months+techPart

I am testing it on this string

newString='Mar. 31, 2011 Dec. 31, 2010 bananas Mar. 31, 2011 too much malarky September 1, 1992 redundant Dec. 31, 2010  September 29, 1999  March 12 2004 ddfd  March.    13 2019 ddfd  Mac.    13 2019 ddfd'

and when I run it like this

for date in re.findall(dateExpr,newString):
print date

I get this

Mar. 31, 2011
Dec. 31, 2010
Mar. 31, 2011
September 1, 1992
Dec. 31, 2010
September 29, 1999
March 12 2004
March.    13 2019
Mac.    13 2019    #here is my problem
  • 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-12T02:59:24+00:00Added an answer on June 12, 2026 at 2:59 am

    In your months regex, you are using square brackets, giving something like [Jan|Feb|Mar|...]. That is wrong. Square brackets are for character classes and match one of any character in the brackets, so this will match J or a or n or | or F, etc. Instead you want to use parentheses:

    months='(?:'+'|'.join(calendar.month_abbr[1:])+'|'+'|'.join(calendar.month_name[1:])+')'
    

    You need the ?: because findall returns only captured groups, so we need to mark this group as noncapturing.

    You have the same problem later in your regex where you do [1|2]. You want (?:1|2), or just [12].

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

Sidebar

Related Questions

I'm trying to utilize setDebugFlags as recommended here to scan for opengl errors: http://developer.android.com/resources/articles/glsurfaceview.html
I'm trying to scan some pictures together (personal 3x4 cm images) and then split
I have some tasks on a site in php using nginx that I'm trying
After a quick scan of related questions on SO, I have deduced that there's
I am currently trying to get ZXing to scan some barcodes. It's doing that
I am trying to scan my harddrive for jpg and mp3 files. I have
Hi i have been trying this for some time now no result yet. i
Trying to compare some dates in java but can't get the formatting right, where
I have some mpeg s from my camcorder and I'm trying to figure out
I have some code that I am trying to make it play nicely with

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.