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

  • Home
  • SEARCH
  • 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 8553681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:42:30+00:00 2026-06-11T14:42:30+00:00

I am trying to make a small sinatra example that will print a calendar

  • 0

I am trying to make a small sinatra example that will print a calendar view for either a month, day or year depending on the URL. Such that

localhost:4567/calendar/2012 will print a year view calendar

localhost:4567/calendar/2012/9 will print a month calendar

localhost:4567/calendar/2012/9/15 will print a day view calendar

I have this working as this:

require 'sinatra'

get '/calendar/:year/:month/:day/?' do
    "printing daily calendar for #{params[:year]}/#{params[:month]}/#{params[:day]}"
end

get '/calendar/:year/:month/?' do
    "printing monthly calendar for #{params[:year]}/#{params[:month]}"
end

get '/calendar/:year/?' do
    "printing yearly calendar for #{params[:year]}"
end

My question is, can I further refine those routes with some kind of RegEx so that I can say the url only counts if the :month portion is between 1 and 12 and the :day portion is between 1 and 31?

  • 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-11T14:42:31+00:00Added an answer on June 11, 2026 at 2:42 pm

    Yes. You can specify regex in sinatra routing condition. See sinatra readme for more information.

    get %r{/calendar/([\d]+)/(1[0-2]|0?[1-9])/([12][0-9]|3[0-1]|0?[1-9])$} do 
      "hello #{params[:captures]}"
    end
    
    get %r{/calendar/([\d]+)/(1[0-2]|0?[1-9])$} do 
      "hello #{params[:captures]}"        
    end
    
    # host/2012/11 will print "hello [2012, 11]"
    # params[:captures] will return an array containing what match the regular expressions
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

'm trying to make a small modification to django lfs project, that will allow
I'm trying to make a small program that will show a video from a
im trying to make a small name summary function depending on the size of
I'm trying to make a small Python script that is executed by clicking an
I'm trying to make a small program that could intercept the open process of
i m trying to make small test driven example by using cppunit. So i
Im trying to make a small app in c++ that saves midifiles with this
I'm trying to make a small VBScript that compacts a MS Access 2007 database
i'm trying to make a small project that uses multiple forms (dialogs) for different
I am trying to make some small additions to some old java code that

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.