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

  • Home
  • SEARCH
  • 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 4613818
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:36:29+00:00 2026-05-22T01:36:29+00:00

I have a lot of documents that look like this: foo_1 foo_2 foo_3 bar_1

  • 0

I have a lot of documents that look like this:

foo_1 foo_2

foo_3

bar_1 foo_4 ...

And I want to convert them by taking all instances of foo_[X] and replacing each of them with foo_[X+1]. In this example:

foo_2 foo_3

foo_4

bar_1 foo_5 ...

Can I do this with gsub and a block? If not, what’s the cleanest approach? I’m really looking for an elegant solution because I can always brute force it, but feel there’s some regex trickery worth learning.

  • 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-22T01:36:30+00:00Added an answer on May 22, 2026 at 1:36 am

    I don’t know Ruby (at all), but something similar to this should work:

    "foo_1 foo_2".gsub(/(foo_)(\d+)/) {|not_needed| $1 + ($2.to_i + 1).to_s}
    

    LE: I actually made it work: http://codepad.org/Z5ThOvTr

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

Sidebar

Related Questions

I have to index a lot documents that contain reference numbers like aaa.bbb.ddd-fff. The
I have a CouchDB (1.1.1) server running that contains a lot of documents in
I have an xml document that looks something like this <?xml version=1.0 encoding=UTF-8?> <mapPoints>
I have config files and various documents that I want to copy from the
I have a sharepoint with a lot of documents stored in it. I would
We have lot of object with this kind of design : Interface and several
If we want to search a query like this t1 t2 t3 (t1,t2 ,t3
I need to have the ability to convert and merge various documents into a
Ok, so I have an iPhone application that displays Word documents for certain terms
I am sorry, if this question sounds stupid, but I have searched a lot

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.