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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:45:16+00:00 2026-05-25T06:45:16+00:00

consider following scenario input string = WIPR.NS i have to replace this with WIPR2.NS

  • 0

consider following scenario

input string = "WIPR.NS"

i have to replace this with “WIPR2.NS”

i am using following logic.

match pattern =  "(.*)\.NS$"    \\ any string that ends with .NS

replace pattern = "$12.NS"

In above case, since there is no group with index 12, i get result $12.NS

But what i want is “WIPR2.NS”.

If i don’t have digit 2 to replace, it works in all other cases but not working for 2.

How to resolve this case?

Thanks in advance,
Alok

  • 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-25T06:45:17+00:00Added an answer on May 25, 2026 at 6:45 am

    Usually depends entirely on your regex engine (I’m not familiar with those that use $1 to represent a capture group, I’m more used to \1 but you’d have the same problem with that).

    Some will provide a delimiter that you can use, like:

    replace pattern = "${1}2.NS"
    

    which clearly indicates that you want capture group 1 followed by the literal 2.NS.


    In fact, by looking at this page, it appears that’s exactly the way to do it (assuming .NET):

    To replace with the first backreference immediately followed by the digit 9, use ${1}9. If you type $19, and there are less than 19 backreferences, the $19 will be interpreted as literal text, and appear in the result string as such.


    Also keep in mind that Jay provides an excellent answer for this specific use case that doesn’t require capture groups at all (by just replacing .NS with 2.NS).

    You may want to look into that as a possibility – I’ll leave this answer here since:

    • it’s the accepted answer; and
    • it probably better for the more complex cases, like changing X([A-Z])4([A-Z]) with X${1}5${2}, where you have variable text on either side of the bit you wish to modify.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be a novice question. :). Consider the following scenario. Suppose we have
Consider following scenario: I have RESTful URL /articles that returns list of articles user
Consider the following scenario . I have an array of numbers: [ 1,2,3,4 ]
From couple of days i am thinking of a following scenario Consider I have
Consider this scenario: I've an XML file called person.xml with the following data in
Let's consider the following scenario. I have the following page where all rendered elements
consider the following scenario: I have a storyboard-based app. I add a ViewController object
Original Question Consider the following scenario: public abstract class Foo { public string Name
Consider the following scenario: (The following things have been omitted: Constructors, Getters and Setters,
Consider the following scenario. I have a table (a stupid_table ) in a schema

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.