For example, let's say I want to take the string Hello World and use a -replace to output "World1". This was my attempt at the expression:
"Hello World" -replace '.*(World)','$11'
But the problem here is that it's seeing $11 as the 11th sequence, not $1 followed by 1. I've tried searching for an escape character to specify that I want a 1 following the $1, but haven't found anything.
The real world problem I was trying to solve is to take a bunch of email addresses and create aliases with a number on the end. For example
[email protected]
becomes
[email protected]
[email protected]
Try "Hello World" -replace '.*(World)','${1}1'
It seemed to work here
var s1 = "Hello World";
var r = ".*(World)";
var p = "${1}1";
var outstr = Regex.Replace(s1, r, p);
Console.WriteLine(outstr);
Output World1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With