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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:07:21+00:00 2026-05-23T09:07:21+00:00

Supposing I have the following text: Lorem ipsum dolor sit amet, consectetur adipisicing elit,

  • 0

Supposing I have the following text:

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod ,,,,,,tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis ,,,,,nostrud exercitation ullamco [,] laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu [,,,,,] fugiat nulla pariatur. Excepteur sint {,,}occaecat cupidatat non proident, sunt {,,,,,} in culpa qui officia deserunt mollit anim id ,,,,,est laborum.

I would like to select all commas in the text with the following pattern

(\,{2,99})

but then I also would like to specify the same filter to be applied only between specific characters like selecting only the commas between [] or {} but not [} for example.

where this would fail:

(\[|\{)  (\,{2,99})  (\]|\})

and the following would work as expected

(\{)  (\,{2,99})  (\})  |  (\[)  (\,{2,99})  (\])

so the thing is that I am having to re-type (\,{2,99}) every time I want to surround this match with another selection.

Is there any way to declare inside the same command a variable that could be applied later on? like:

$1=(\,{2,99}) | (\{$1\}) | (\[$1\])

I hope this is easy to understand, please bear with me since regular expersions are really a new thing in my case, so all these declarations might look terrible for you 🙂

I would appreciate if you could notice something badly written here and recommend a better way to it.

Please also mind that this example for catching all the commas was for demonstrative purposes on how I would like to re-use a bit of code more times inside the same command…you could replace that simple selector with something huge that you wouldn’t like to re-type every time?

Thanks in advance

  • 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-05-23T09:07:21+00:00Added an answer on May 23, 2026 at 9:07 am

    You can use a variable and concatenate it several times with your regex.

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

Sidebar

Related Questions

Supposing I have the following LambdaExpression: var itemParam = Expression.Parameter(typeof(Thing), thing); var someValue =
Supposing I have the following type from an external library: union foreign_t { struct
Supposing I have a MySQL table (meta_table) as follows with the following data: meta_id,post_id,meta_key,meta_value
Supposing I have the following action: def index @posts = Post.joins(:tags).where(:tags => {:id =>
supposing I have the following data: id name source ----------------- 1 'n' 'a' 1
Supposing I have the following list: A | B | C | D or
Supposing we have the following records in an SQL Server table. Date 19/5/2009 12:00:00
Supposing I have the following rows: VARIABLENAME YYYYMM XXXXYY DATAOBS variable_1 | 201101 |
Supposing I have the following code which returns a Javascript object which I can
Supposing I have a table with the following schema: int pitchId, int pitcherId, int

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.