I am noticing some really strange behavior with Regex replacements and
am wondering if anyone can help me make any sense of it.
Let's say we have a string "Price=#InsertPrice#" and we want to
replace "#InsertPrice# with one or more "$" symbols to denote the
price level.
Now, here's what I'm seeing when I try the following replacement
strings:
Replacement String Output
---------------------------------------------------------------------------------------
"$" -> "Price=
$"
"$$" -> "Price=
$"
"$$$" -> "Price=$
$"
What appears to be happening is that it's truncating the first "$"
when the output string is being built.
My first thought is that this might be because the "$" symbol is a
special character used for substitutions and I needed to escape it.
But when I try to escape it, it doesn't work either. I get:
@"\$\$" -> "Price=\$\
$"
At this point I have no idea what is going on here and all I can think
of is that this must be a bug. Any ideas?
Arne Vajhøj - 29 Apr 2008 03:25 GMT
> I am noticing some really strange behavior with Regex replacements and
> am wondering if anyone can help me make any sense of it.
[quoted text clipped - 10 lines]
> "$" -> "Price=
> $"
May we see a code snippet illustrating the problem ?
Arne
Alain Boss - 29 Apr 2008 08:51 GMT
Alphamacaroon schrieb:
> I am noticing some really strange behavior with Regex replacements and
> am wondering if anyone can help me make any sense of it.
[quoted text clipped - 27 lines]
> At this point I have no idea what is going on here and all I can think
> of is that this must be a bug. Any ideas?
your problem might be that '/' is also a special c# character. please
post some code, as arne suggested, or try your regex using @"" for your
regex-definition.
alain
Jesse Houwing - 29 Apr 2008 19:45 GMT
Hello Alphamacaroon,
> I am noticing some really strange behavior with Regex replacements and
> am wondering if anyone can help me make any sense of it.
[quoted text clipped - 27 lines]
> At this point I have no idea what is going on here and all I can think
> of is that this must be a bug. Any ideas?
$ is indeed special in a replaceemnt string. And you can escape it (as you've
already done in your second example) by doubling it up, like this: $$.
--
Jesse Houwing
jesse.houwing at sogeti.nl
Alphamacaroon - 29 Apr 2008 20:15 GMT
On Apr 29, 11:45 am, Jesse Houwing <jesse.houw...@newsgroup.nospam>
wrote:
> Hello Alphamacaroon,
>
[quoted text clipped - 36 lines]
> Jesse Houwing
> jesse.houwing at sogeti.nl
Ahhh. Makes sense. So unlike RegEx Pattern strings where the escape
char is '\', the escape char for the replacement string is '$' itself.
I'll give it a try, but I suspect that will fix it. Thanks!
BTW: Is this documented anywhere?