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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:31:53+00:00 2026-06-10T20:31:53+00:00

What would this mean in an expression? (?m:.*?) or this (?m:\s*) I mean, it

  • 0

What would this mean in an expression?

(?m:.*?)

or this

(?m:\s*)

I mean, it appears to be something to do with whitespace but I’m unsure.

ADDITIONAL DETAILS:
The full expression I’m looking at is:

\A((?m:\s*)((\/\*(?m:.*?)\*\/)|(\#\#\# (?m:.*?)\#\#\#)|(\/\/ .* \n?)+|(\# .* \n?)+))+
  • 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-10T20:31:54+00:00Added an answer on June 10, 2026 at 8:31 pm

    (?...) is a way of applying modifiers to the regular expression inside the parentheses.

    (?:...) allows you to treat the part between the parentheses as a group, without affecting the set of strings captured by the matching engine. But you can add option letters between the ? and the :, in which case the part of the regular expression between the parentheses behaves as if you had included those option letters when creating the regular expression. That is, /(?m:...)/ behaves the same as /.../m.

    The m, in turn, enables “multiline” mode.

    CORRECTED:

    Here’s where I got confused in the original answer, because this option has different meanings in different environments.

    This question is tagged Ruby, in which “multiline mode” causes the dot character (.) to match newlines, whereas normally that’s the one character it doesn’t match:

    irb(main):001:0> "a\nb" =~ /a.b/
    => nil
    irb(main):002:0> "a\nb" =~ /a.b/m
    => 0
    irb(main):003:0> "a\nb" =~ /(?m:a.b)/
    => 0
    

    So your first regular expression, (?m:.*?) will match any number (including zero) of any characters (including newlines). Basically, it will match anything at all, including nothing.

    In the second regular expression, (?m:\s*), the modifier has no effect at all because there are no dots in the contained expression to modify.

    Back to the first expression. As Ωmega says, the ? after the * means that it is a non-greedy match. If that were the whole expression, or if there were no captures, it wouldn’t matter. But when something follows that section and there are captures, you get different results. Without the ?, the longest possible match wins:

    irb(main):001:0> /<(.*)>/.match("<a><b>")[1]
    => "a><b"
    

    With the ?, you get the shortest one instead:

    irb(main):002:0> /<(.*?)>/.match("<a><b>")[1]
    => "a"
    

    Finally, about the above-mentioned /m confusion (though if you want to avoid becoming confused yourself, this might be a good place to stop reading):

    In Perl 5 (which is the source of most regular expression extensions beyond the basic syntax), the behavior triggered by /m in Ruby is instead triggered by the /s option (which Ruby doesn’t have, though if you put one on your regex it will silently ignore it). In Perl, /m, despite still being called “multiline mode”, has a completely different effect: it causes the ^ and $ anchors to match at newlines within the string as well as at the beginning and end of the whole string respectively. But in Ruby, that behavior is the default, and there’s not even an option to change it.

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

Sidebar

Related Questions

Why would this work timeout 10s echo foo bar # foo bar but this
I have read that you can do it, but would this really improve performance
What does the expression Fail Early mean, and under what circumstances is this approach
I know this question seems stupid, but it isn't. I mean what is it
Would this be a proper way to dispose of a BackGroundWorker? I'm not sure
Would this be the correct way of declaring that an XML element Cluster contains
For a login system in php would this be a suitable outline of how
In a single paged application, would this be the best way to bind and
I'd like to enable SVNAutoversioning for one repository only. Would this work? <Location /repos/>
Say I have a table with an auto-incrementing surrogate key. Would this be a

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.