开发者

Need help with regular expression to transform code

I have an enormous list of the following items:

    _tags.Add(Foo.Bar,
                  new Baz(
                      ...
                      ));

        _tagNames.Add("Bar",
                  _tags[Foo.Bar]);

wh开发者_如何转开发ere Bar and Baz(...) vary, and _tags, _tagNames and Foo stay the same.

I want to transform to

    case "Bar":
        _tags.Add(Foo.Bar,
                  new Baz(
                      ...
                      ));

        _tagNames.Add("Bar",
                  _tags[Foo.Bar]);

        break;

I am using Visual Studio, which supports regex.

Any ideas?

Thanks!

Update: VS couldn't handle 2300 instances of this regex. I got this working in Eclipse:

Search Pattern: _tags.Add((?:.|\R)*?_tags[Foo.(.*?)]);

Replace: case "\1":\n\0\n break;


Tested on VS 2008:

_tags\.Add\((.|\n)@_tags\[Foo\.{(.@)}\]\);

Whith this as replacement string:

case "\1":\n\0\nbreak;

You might have to insert some tab-characters to keep your indention (or use auto-format).

UPDATE:

Tested and fixed regex for usage in vs

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜