+ Reply to Thread
Results 1 to 2 of 2

Thread: Replace using backreference

  1. #1

    Replace using backreference

    I have some DNA records that is like that :
    Code:
    DNA[1]/Record[1]
    DNA[1]/Another Record[1]
    Records can be like thousands , so what i need to do is replacing the Record number with mine
    So for example it looks like that :
    Code:
    DNA[1]/Record[17]
    DNA[1]/Another Record[17]
    So i tried :
    Code:
    DNA\[1\]/.*\[([0-9])\]
    P.S : i use C#
    Last edited by basemhosam; 07-24-2012 at 09:51 PM.

  2. #2
    Junior Member
    Join Date
    Jun 2012
    Posts
    41
    The pattern should be :
    Code:
    (?<=DNA\[1\]/.*\[)\d(?=\]")
    Implement it in C# to look like that :
    Code:
    string DNARecord = "DNA[1]/Record[1]";
    int NewNumber = 17;
    DNARecord = Regex.Replace(DNARecord, @"(?<=project\[1\]/.*\[)\d(?=\]"")", NewNumber.ToString());

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts