Bala R
Bala R

Reputation: 108937

c# regex replace

Consider a string like this,

type="xxx.yyy.zzz, xxx.yyy, Version=2.0.3.0, Culture=neutral, PublicKeyToken=null"

I read a resx file and would like to replace all occurrences of the above string with String.Empty no matter what the Version is, but the version format will remain the same and the rest of the string does not change. I tried a few things but I'm in a bit of a crunch; and would really appreciate any help on this. Thanks.

Upvotes: 1

Views: 231

Answers (1)

Amarghosh
Amarghosh

Reputation: 59451

type="xxx\.yyy\.zzz, xxx\.yyy, Version=\d+\.\d+\.\d+\.\d+, Culture=neutral, PublicKeyToken=null"
  • \d stands for a digit; \d+ matches one or more digits.
  • . is a special character and needs to be escaped as \.

As a c# regex string, it'd look like:

pattern = "type=\"xxx\\.yyy\\.zzz, xxx\\.yyy, Version=\\d+\\.\\d+\\.\\d+\\.\\d+, Culture=neutral, PublicKeyToken=null\"";

Upvotes: 1

Related Questions