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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:39:08+00:00 2026-05-26T03:39:08+00:00

I am using my texteditor (e-texteditor)’s regular expression to try to reverse some elements

  • 0

I am using my texteditor (e-texteditor)’s regular expression to try to reverse some elements in a line of code. So here’s what I have:

  [[Date.today, "Today (#{Date.today})"], [Date.tomorrow, "Tomorrow (#{Date.tomorrow})"], [Date.today+3, "In 3 Days (#{Date.today+3})"], [this_weekend, "This Weekend (#{this_weekend})"]]

And I actually wanted it the reverse of it:

  [[this_weekend, "This Weekend (#{this_weekend})"], [Date.today+3, "In 3 Days (#{Date.today+3})"], [Date.tomorrow, "Tomorrow (#{Date.tomorrow})"], [Date.today, "Today (#{Date.today})"]]

By the way, the code is in Ruby in case you’re wondering. To visualize better:

Have: [A, B, C, D]
Want: [D, C, B, A]

So far, I am doing the dumb thing (or at least I think so) by searching for

 (\[[^[].+?\]),\s(\[[^[].+?\]),\s(\[[^[].+?\]),\s(\[[^[].+?\]) 

so it’s like search for (A),\s(B),\s(C),\s(D)

And then replace it with

  $4, $3, $2, $1

While that works, but it’s not very nice isn’t it, what if I have more than 4 elements. That’s a lot of typing up still. How will you approach it?

Here is the regex ‘engine/syntax’ that e-texteditor supports
enter image description here

Thank you!

  • 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-26T03:39:08+00:00Added an answer on May 26, 2026 at 3:39 am

    This (\[[^[].+?\]), could be a problamatic subexpression.
    It works in this case because the sample data you provide is
    well formed. In ill-formed context, it could overflow to the next ],
    if not preceded by a [, even though .+? is non greedy.

    It might be better as this (\[[^\[\]]+\]).

    To your question, I think that only .NET has variable amount of
    capture buffers (its Capture Collection) and even then I’m not sure
    how its variability could be used on the replacement side.
    Example: \[(?:(\[[^\[\]]+\])(?:,\s*|(?=\])))+\] should make
    a variable collection that you may be able to programatically
    reverse on the replacement side. I’ve never done this so not
    too sure.

    Otherwise, it involves a couple of seperate intermediate steps
    outside of a regex.

    In Perl, it’d be like use global search and replace, where the
    replacement side is a callback function that gets passed each individual record.

    s/(\[(?:\[[^\[\]]+\](?:,\s*|(?=\])))+\])/ func($1) /eg;`

    Then in the callback, parse the individual elements from the record passed, then
    rebuild the string in reverse order, which then gets passed back to the original
    regex to be used as the replacement for that record.

    Perl code:

    use strict;
    use warnings;
    
    my $samp = '[[Date.today, "Today (#{Date.today})"], [Date.tomorrow, "Tomorrow (#{Date.tomorrow})"], [Date.today+3, "In 3 Days (#{Date.today+3})"], [this_weekend, "This Weekend (#{this_weekend})"]]';
    
    $samp =~ s/(\[(?:\[[^\[\]]+\](?:,\s*|(?=\])))+\])/ func($1) /eg;
    
    print "\n$samp\n";
    
    
    sub func
    {
       my $rec = shift;
       my @elements = $rec =~ /(\[[^\[\]]+\])/g;
       return '['. join( ', ', reverse @elements ) . ']';
    }
    

    Output:

    [[this_weekend, "This Weekend (#{this_weekend})"], [Date.today+3, "In 3 Days (#{Date.today+3})"], [Date.tomorrow, "Tomorrow (#{Date.tomorrow})"], [Date.today, "Today (#{Date.today})"]]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Custom Control registered in the page using this code: <%@ Register
I'm using the ICSharpCode.TextEditor and want to change the syntax colors... in the namespace
I have recently started using Vim as my text editor and am currently working
I want to view the HTML source of a web page, I've using ICSharpCode.TextEditor,
I have a problem as follows: We're using a rich text editor (TinyMCE, but
I've been using the ICSharp TextEditor control, and this uses an XML file to
For some reason our adhoc provisioning profile just won't have the aps-environment entitlement! We've
I'm trying to implement undo/redo feature in my custom application that displays code using
I am creating a texteditor in c++[non gui] , So far i have ended
I have a DotNetNuke custom module where I am using an HTML editor to

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.