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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:14:20+00:00 2026-05-22T22:14:20+00:00

is there a string in regular expressions that can instruct it to autoincrement it’s

  • 0

is there a string in regular expressions that can instruct it to autoincrement it’s replacements, whether they be numbers or letters.

Thank you

for instance, I have strings that should be number 1, 2, 3, 4, 5 but they are currently numbered as 1, 1, 1, 1, 1

how would I replace the number in those 5 individual similar strings to be 1, 2, 3, 4, 5

  • 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-22T22:14:20+00:00Added an answer on May 22, 2026 at 10:14 pm

    I’m not familiar with the syntax of TextWrangler; however, it uses pcre so this should be what you want as long as you have a way to assign an initial value to your incrementing variable (in this case, I use $ii)… the script below replaces any occurrence of “pizza-x” with “pizza-0”, “pizza-1″…

    @foo = ('pizza', 'pizza-a', 'pizza-b', 'pizza-c');
    $ii = 0;
    foreach (@foo) {
        $_ =~ s/(pizza-)[a-z]/"$1".$ii++/e;
        print "$_\n";
    }
    

    Results…

    [mpenning@mpenning-t60 Desktop]$ perl foo.pl 
    pizza
    pizza-0
    pizza-1
    pizza-2
    

    The magic comes from s///e; and $ii++; be sure you enclose the non-incrementing string in quotes and concatenate with a period.

    Alternatively, just do your auto-increment mangling with perl -pi -e '$ii = 0; s/something/"here".$ii++/e ` directly on the text file (make a backup copy first, of course).

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

Sidebar

Related Questions

Is there a Regular Expression that can detect SQL in a string? Does anyone
Is there a single regular expression that can parse a string (in Python and/or
How can I convert a string to a regular expression that matches itself in
Is there a format string (?) I can pass to the VB6 Format function
Is there a PHP string function that transforms a multi-line string into a single-line
I am doing some fairly extensive string manipulations using regular expressions in Java. Currently,
Possible Duplicate: Regular Expressions: Is there an AND operator? I let my users enter
If I have a list of regular expressions, is there an easy way to
I'm new to regular expressions in Java (or any language, for that matter) and
I have strings like: http://127.0.0.1:22/Test Is there some single function maybe using regular expressions

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.