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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:24:44+00:00 2026-06-11T04:24:44+00:00

In a model there is a field validates :image_file_name, :format => { :with =>

  • 0

In a model there is a field

validates :image_file_name, :format => { :with => %r{\.(gif|jpg|jpeg|png)$}i

It looks pretty odd for me. I am aware that this is a regular expression. But I would like:

  • to know what exactly it means. Is %r{value} equal to /value/ ?
  • be able to replace it with normal Ruby regex operator /some regex/ or =~. Is this possible?
  • 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-11T04:24:45+00:00Added an answer on June 11, 2026 at 4:24 am

    %r{} is equivalent to the /.../ notation, but allows you to have ‘/’ in your regexp without having to escape them:

    %r{/home/user}
    

    is equivalent to:

    /\/home\/user/
    

    This is only a syntax commodity, for legibility.

    Edit:

    Note that you can use almost any non-alphabetic character pair instead of ‘{}’.
    These variants work just as well:

    %r!/home/user!
    %r'/home/user'
    %r(/home/user)
    

    Edit 2:

    Note that the %r{}x variant ignores whitespace, making complex regexps more readable. Example from GitHub’s Ruby style guide:

    regexp = %r{
      start         # some text
      \s            # white space char
      (group)       # first group
      (?:alt1|alt2) # some alternation
      end
    }x
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a Backbone model with a custom validate method that validates the format
I have added a 'cancelled' field to my model, is there a way to
I have a very simple model that includes the auto-filled field much like 'created'.
is there something like: validates_value_of :verified,:with=>1 to validate the boolean field on the model?
There is field name active in customer table. It validates as below in customer.rb:
I have an ActiveRecord model whose fields mostly come from the database. There are
I have a model with a first_name and last_name field, and these are used
In my model there are an entity generator, some attribute function(out_attrName) and an entity
Say I've a user model and there are bunch of user info, like email,
I am working with the output from a model in which there are parameter

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.