Help on replacement string to insert numbers between matching groups (regular expression)

Activity: UiPath.Core.Activities.Replace
Input = “123456”
Pattern = “(\d{2})(\d{4})”
Replacement(erroneous string) = “$199$2”
Desired Result = “12993456”

I am getting an error with this. What replacement string should I use to get the desired result?

Your kind help would be appreciated.

assuming txt = “123456”

assign first2Digit (string variable ) = system.Text.RegularExpressions.Regex.match(txt, "(\d{2})\d{4}").Groups(1).Value

then
result = txt.Replace(first2Digit, first2Digit+"99")

TEST.xaml (14.5 KB)

Thanks Jack. But is there replacement string for the activity uipath.core.activities.replace that gets the desired result?

sorry i dont understand your question @Bartok

Hi @Bartok ,

You could perform this operation by directly using Regex.Replace method or using the Replace Activity as mentioned in doc below.

Let us know if you need further help.

@Bartok Try the below expression,
where Input = “1234567”

String Result = String.Concat(System.Text.RegularExpressions.Regex.Match(Input,“(\d{2}(\d{4})”).Groups(1).Value,“99”,System.Text.RegularExpressions.Regex.Match(Input,“(\d{2})(\d{4})”).Groups(2).Value)

Result will be as you want

Result = “123994567”

Thanks,
Shaik Najeer.