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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:04:52+00:00 2026-06-03T04:04:52+00:00

I am trying to use regular expressions in a ruby on rails app to

  • 0

I am trying to use regular expressions in a ruby on rails app to search through a given string and find any instances of opening and closing square brackets, (ie [ and ]) and select the contents between the two.

For example:

Lorem ipsum [dolor sit] amet...

In this string the result would be: [dolor sit]

I played around with rubular a bit and found that this more or less does what I want

/\[.*?\]/

So my question is, how do i match everything within the two square brackets without selecting the brackets themselves? And also how do I actually integrate them into a ruby script?

Regular expressions are totally new ground for me so any help you guys can offer would be much appreciated 🙂

  • 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-03T04:04:53+00:00Added an answer on June 3, 2026 at 4:04 am

    Collecting multiple captures of a regexp is a job for String#scan

    >> s="Lorem ipsum [dolor sit] [amet] ..."
    => "Lorem ipsum [dolor sit] [amet] ..."
    >> s.scan(/\[([^\]]*)\]/).flatten
    => ["dolor sit", "amet"]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use regular expressions in R to find one or more phrases
I'm trying to use regular expressions to match a string that does not contain
I'm trying to use regular expressions to find three or more of the same
I am trying to use ack-is-better-than-grep (ack) with regular expressions to find lines and
I am trying to use regular expressions to find a UK postcode within a
I'm trying to use the find/adding/removing string/regular expression option in gitk. The syntaxes I
I have never been any good at regular expressions. I am trying to use
Hi I'm new to Ruby and regular expressions. I'm trying to use a regular
I'm trying to find a single regular expression that I can use to parse
I am trying to use regular expressions to determine what format the user have

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.