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

The Archive Base Latest Questions

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

Ruby regexp has some options (e.g. i , x , m , o ).

  • 0

Ruby regexp has some options (e.g. i, x, m, o). i means ignore case, for instance.

What does the o option mean? In ri Regexp, it says o means to perform #{} interpolation only once. But when I do this:

a = 'one'  
b = /#{a}/  
a = 'two'  

b does not change (it stays /one/). What am I missing?

  • 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-14T02:51:00+00:00Added an answer on June 14, 2026 at 2:51 am

    Straight from the go-to source for regular expressions:

    /o causes any #{...} substitutions in a particular regex literal to be performed just once, the first time it is evaluated. Otherwise, the substitutions will be performed every time the literal generates a Regexp object.

    I could also turn up this usage example:

    # avoid interpolating patterns like this if the pattern
    # isn't going to change:
    pattern = ARGV.shift
    ARGF.each do |line|
        print line if line =~ /#{pattern}/
    end
    
    # the above creates a new regex each iteration. Instead,
    # use the /o modifier so the regex is compiled only once
    
    pattern = ARGV.shift
    ARGF.each do |line|
        print line if line =~ /#{pattern}/o
    end
    

    So I guess this is rather a thing for the compiler, for a single line that is executed multiple times.

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

Sidebar

Related Questions

Using ruby regexp I get the following results: >> 'foobar'[/o+/] => oo >> 'foobar'[/o*/]
I am reading one file using ruby in which I have written regexp in
Ruby compacts the sequence only if it has nil value, how do I compact
Ruby has a select method that takes an array and returns a subarray consisting
I've a Ruby regexp question. if string == /(^\d{1,3})/ # this matches both 24
I understand how to check for a pattern in string with regexp in ruby.
I wan't to make a string regexp safe in Ruby. I have: comment =
I'm trying to fix a subtitles (.srt) text file that has some incorrect data
I'm trying the following tutorial: http://henrik.nyh.se/2007/03/ruby-wordwrap-method It has a block that needs to be
jruby-head version.rb @ /.rvm/rubies/jruby-head/lib/ruby/shared/rubygems/version.rb has the following regex: VERSION_PATTERN = '[0-9]+(\.[0-9a-zA-Z]+)*' # :nodoc: This

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.