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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:08:56+00:00 2026-05-15T16:08:56+00:00

I am trying to write some code that will function like google calendars quick

  • 0

I am trying to write some code that will function like google calendars quick add feature . You know the One where you can input any of the following :
1) 24th sep 2010 , Johns Birthday
2) John’s Birthday , 24/9/10
3) 24 September 2010 , Birthday of John Doe
4) 24-9-2010 : John Does Birthday
5) John Does Birthday 24th of September 2010

And it can figure out that we want an event on a date 24/9/2010 have the rest of the material as the event text.

I want to do this is python .

I am thinking of a design where I write regular expressions that may match all of the cases listed above and extract the date. But I am sur there is a smarter way to approach this problem . Since I clearly am not trained in lexical analysis or the many types of parsers styles. I am looking for whats a good way to approach this 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-05-15T16:08:57+00:00Added an answer on May 15, 2026 at 4:08 pm

    NOTE: The python code here is not correct! It is just a rough pseudo-code of how it might look.

    Regular Expressions are good at finding and extracting data from text in a fixed format (e.g. a DD/MM/YYYY date).

    A lexer/parser pair is good at processing data in a structured, but somewhat variable format. Lexers split text into tokens. These tokens are units of information of a given type (number, string, etc.). Parsers take this series of tokens and does something depending on the order of the tokens.

    Looking at the data, you have a basic (subject, verb, object) structure in different combinations for the relation (person, ‘birthday’, date):

    I would handle 29/9/10 and 24-9-2010 as a single token using a regex, returning it as a date type. You could probably do the same for the other dates, with a map to convert September and sep to 9.

    You could then return the everything else as strings (separated by whitespace).

    You then have:

    1. date ‘,’ string ‘birthday’
    2. string ‘birthday’ ‘,’ date
    3. date ‘birthday’ ‘of’ string string
    4. date ‘:’ string string ‘birthday’
    5. string string ‘birthday’ date

    NOTE: ‘birthday’, ‘,’, ‘:’ and ‘of’ here are keywords, so:

    class Lexer:
        DATE = 1
        STRING = 2
        COMMA = 3
        COLON = 4
        BIRTHDAY = 5
        OF = 6
    
        keywords = { 'birthday': BIRTHDAY, 'of': OF, ',': COMMA, ':', COLON }
    
        def next_token():
            if have_saved_token:
                have_saved_token = False
                return saved_type, saved_value
            if date_re.match(): return DATE, date
            str = read_word()
            if str in keywords.keys(): return keywords[str], str
            return STRING, str
    
        def keep(type, value):
            have_saved_token = True
            saved_type = type
            saved_value = value
    

    All except 3 use the possessive form of the person ('s if the last character is a consonant, s if it is a vowel). This can be tricky, as ‘Alexis’ could be the plural form of ‘Alexi’, but since you are restricting where plural forms can be, it is easy to detect:

    def parseNameInPluralForm():
        name = parseName()
        if name.ends_with("'s"): name.remove_from_end("'s")
        elif name.ends_with("s"): name.remove_from_end("s")
        return name
    

    Now, name can either be first-name or first-name last-name (yes, I know Japan swaps these around, but from a processing perspective, the above problem does not need to differentiate first and last names). The following will handle these two forms:

    def parseName():
        type, firstName = Lexer.next_token()
        if type != Lexer.STRING: raise ParseError()
        type, lastName = Lexer.next_token()
        if type == Lexer.STRING: # first-name last-name
            return firstName + ' ' + lastName
        else:
            Lexer.keep(type, lastName)
            return firstName
    

    Finally, you can process forms 1-5 using something like this:

    def parseBirthday():
        type, data = Lexer.next_token()
        if type == Lexer.DATE: # 1, 3 & 4
            date = data
            type, data = Lexer.next_token()
            if type == Lexer.COLON or type == Lexer.COMMA: # 1 & 4
                person = parsePersonInPluralForm()
                type, data = Lexer.next_token()
                if type != Lexer.BIRTHDAY: raise ParseError()
            elif type == Lexer.BIRTHDAY: # 3
                type, data = Lexer.next_token()
                if type != Lexer.OF: raise ParseError()
                person = parsePerson()
        elif type == Lexer.STRING: # 2 & 5
            Lexer.keep(type, data)
            person = parsePersonInPluralForm()
            type, data = Lexer.next_token()
            if type != Lexer.BIRTHDAY: raise ParseError()
            type, data = Lexer.next_token()
            if type == Lexer.COMMA: # 2
                type, data = Lexer.next_token()
            if type != Lexer.DATE: raise ParseError()
            date = data
        else:
            raise ParseError()
        return person, date
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 500k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer This is not pretty but it works: rm -R $(ls… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer Yes. Override the base1 and base2 methods in Derived to… May 16, 2026 at 12:45 pm
  • Editorial Team
    Editorial Team added an answer No, you can't. Unfortunately, UIEvent doesn't expose any public way… May 16, 2026 at 12:45 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to write some simple code that will return the directory for the
I am trying to write some Scala code that needs to do something like:
I'm trying to write some jQuery code that will highlight the element the cursor
I'm trying to write a small Powershell function that will return some summary data
I'm trying to write a piece of code that reads a file line by
I'm trying to write a code that allows a user to load an assembly
I have an OLE COM object that trying to write a wrapper for, I
I am trying to write a unit test using .NET 4 to ensure that
I'm trying to connect to a website (source code below) that requires login and
I am trying to write a socket server that forks for every connection. I

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.