1

I have an enormous list of the following items:

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

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

where 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;

2
  • 1
    Its not clear enoght what you want to do Commented Jun 1, 2011 at 14:09
  • Updated my answer. I tested in on vs2008 and it should work so far. Commented Jun 1, 2011 at 14:52

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

4 Comments

Turns out VS can't handle regex on 1800 instances of this pattern. Can you suggest a scripting language that could process this?
I use regex with PHP and Java. Both should be able to handle many files and even large files if used properly. Unfortunately the setup ist not that quick. If you have an eclipse running or a local xampp you might be lucky.
I got this working in Eclipse: _tags\.Add((?:.|\R)*?_tags[Foo\.(.*?)]); case "\1":\n\0\n break;
Yeah, it did, no probs. Eclipse rocks!

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.