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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T18:32:45+00:00 2026-06-05T18:32:45+00:00

My understanding of regex and working with strings in php is poor at best

  • 0

My understanding of regex and working with strings in php is poor at best so my apologies if this is a simple question for most. If I’m honest the searches I have made have confused me more than anything else, hopefully someone here can give me a clear answer.

I simply need to increment the suffix of file names in PHP.

The file names look like the following:

13132432343243432434234_1.jpg

I wish to keep the file name exactly as is, but replace the final ‘_1’ part with ‘_2’, ‘_3’, ‘_4’ etc.

There is no need to check if the file exists, this needs to be a simple string manipulation. If the suffix is _1, then replace it with _2 and if the suffix is _4, then replace it with _5 etc.

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-06-05T18:32:48+00:00Added an answer on June 5, 2026 at 6:32 pm

    Something along these lines should do it:

    echo preg_replace_callback('/(?<=_)\d+(?=\.)/',
                               function ($m) { return ++$m[0]; },
                               '13132432343243432434234_1.jpg');
    

    The regex matches “any number preceded by a _ and followed by a .“, the callback returns this number incremented by one.

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

Sidebar

Related Questions

I'm having a hard time understanding this regex stuff... I have a string like
Apologies for my poor understanding on the regex world. I'm trying to split a
I have the following regex in a C# program, and have difficulties understanding it:
Well, here I am back at regex and my poor understanding of it. Spent
I have just studied the RegEx and I find myself confusing from this following
I have a RegEx that is working for me but I don't know WHY
This question is Part 2 of PHP's preg_match_all() to pull out all php tags
It is my understanding that the java.regex package does not have support for named
My regex skills are pretty poor, and most of the time they make me
I apologize if this is a trivial question or my understanding of rails is

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.