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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:23:21+00:00 2026-05-16T05:23:21+00:00

I am trying to get a Regex replacement working to update my AssemblyInfo.cs files,

  • 0

I am trying to get a Regex replacement working to update my AssemblyInfo.cs files, so I have:

Regex.Replace(
    contents, 
    @"(\[assembly: Assembly(File)?Version\("").*(""\)\])", 
    "$1" + version + "$3"
);

The problem is that version is something like "1.5.3.0", so that when the replacement is evaluated it is seeing "$11.5.3.0$3" and is presumably looking for the eleventh captured group because it is coming out with:

$11.5.3.0")]

If is stick a space after the $1 it works fine. What do I need to put in there to escape the second digit without actually inserting the character?

  • 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-16T05:23:22+00:00Added an answer on May 16, 2026 at 5:23 am

    Use ${1} instead of $1. This is also the substitution syntax for named capturing group (?<name>).

    Here’s a snippet to illustrate (see also on ideone.com):

    Console.WriteLine(Regex.Replace("abc", "(.)", "$11"));        // $11$11$11
    Console.WriteLine(Regex.Replace("abc", "(.)", "${1}1"));      // a1b1c1
    Console.WriteLine(Regex.Replace("abc", "(?<x>.)", "${x}1"));  // a1b1c1
    

    This behavior is explicitly documented:

    Regular Expression Language Elements – Substitutions

    Substituting a Numbered Group

    The $number language element includes the last substring matched by the number capturing group in the replacement string, where number is the index of the capturing group.

    If number does not specify a valid capturing group defined in the regular expression pattern, $number is interpreted as a literal character sequence that is used to replace each match.

    Substituting a Named Group

    The ${name} language element substitutes the last substring matched by the name capturing group, where name is the name of a capturing group defined by the (?<name>) language element.

    If name does not specify a valid named capturing group defined in the regular expression pattern, ${name} is interpreted as a literal character sequence that is used to replace each match.

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

Sidebar

Related Questions

I am having trouble trying to get some replaces working with my regex. Here
I'm trying to get a regex that will match: somefile_1.txt somefile_2.txt somefile_{anything}.txt but not
I'm stuck trying to get a regex to match a filetype in a sorting
I'm trying to get the following regex to work on my String: Pattern Regex
I'm trying to get all words inside a string using Boost::regex in C++. Here's
I am a bit puzzled with my Regex results (and still trying to get
I am trying to write a regex to get the numbers from strings like
I am trying to write out a regex to get each insert line from
I'm trying to parse phone number with regex. Exactly I want to get a
Yep - another noob regex query, which I can't seem to get. I'm trying

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.