1

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.

1
  • I don't understand: you want to replace the entire line with an empty string if it matches the version? Or if it matches xxx.yyy.zzz? Commented Jul 9, 2010 at 13:38

1 Answer 1

1
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\"";
Sign up to request clarification or add additional context in comments.

8 Comments

Hhm, what if there is a extra space or if version is only specified to x.x.x or if culture is not neutral. I know it is not your Regex there is faulty, but rather the question which lacks some information.
@lasseespeholt OP said rest of the string does not change and I relied on that.
Yes, I know :) Again, I know your regex is not faulty. But will a extra space qualify for "a change"? <- question for Bala R
@lasseespeholt there won't be an extra space.
I'm now struggling with the Unrecognized escape sequence error. Will update once I get it to work.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.