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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T13:33:08+00:00 2026-06-08T13:33:08+00:00

I have a fairly long string that contains sub strings with the following format:

  • 0

I have a fairly long string that contains sub strings with the following format:

project[1]/someword[1]
project[1]/someotherword[1]

There will be about 10 or so instances of this pattern in the string.

What I want to do is to be able to replace the second integer in square brackets with a different one. So the string would look like this for instance:

project[1]/someword[2]
project[1]/someotherword[2]

I”m thinking that regular expressions are what I need here. I came up with the regex:

project\[1\]/.*\[([0-9])\]

Which should capture the group [0-9] so I can replace it with something else. I’m looking at MSDN Regex.Replace() but I’m not seeing how to replace part of a string that is captured with a value of your choosing. Any advice on how to accomplish this would be appreciated. Thanks much.

*Edit: * After working with @Tharwen some I have changed my approach a bit. Here is the new code I am working with:

  String yourString = String yourString = @"<element w:xpath=""/project[1]/someword[1]""/> <anothernode></anothernode> <another element w:xpath=""/project[1]/someotherword[1]""/>";
 int yourNumber = 2;
 string anotherString = string.Empty;
 anotherString = Regex.Replace(yourString, @"(?<=project\[1\]/.*\[)\d(?=\]"")", yourNumber.ToString());
  • 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-08T13:33:11+00:00Added an answer on June 8, 2026 at 1:33 pm

    I’ve adapted yours to use a lookbehind and lookahead to only match a digit which is preceded by ‘project[1]/xxxxx[‘ and followed by ‘]’:

    (?<=project\[1\]/.*\[)\d(?=\]")
    

    Then, you can use:

    String yourString = "project[1]/someword[1]";
    int yourNumber = 2;
    yourString = Regex.Replace(yourString, @"(?<=project\[1\]/.*\[)\d(?=\]"")", yourNumber.ToString());
    

    I think maybe you were confused because Regex.Replace has lots of overloads which do slightly different things. I’ve used this one.

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

Sidebar

Related Questions

I have bunch of strings, some of which are fairly long, like so: movie.titles
I have a project that has a fairly complicated, nested (references calling the referenced
I have a fairly large Excel file. In this file there is a column
I have a fairly lengthly block of code that I'm trying to convert from
I am a fairly exceptional applescripter, and have been writing scripts for a long
I have a fairly long list in python which I want to return parts
I have a Windows service which performs a fairly long running task. At the
I have a fairly long and complex HTML document, and I need to find
I have a database-synchronisation task that takes some time to process, as there are
I have a fairly simple question. There is a named HTML entity in most

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.