0

I want to use regex to do two things:

1.Comment all the strings that call the method .EnterText:

myField1.EnterText( a, 1000 );
myField2.EnterText( b, 3000 );

I have lots of those lines. How can I use regex to achieve something like this in Visual Studio:

//myField1.EnterText( a, 1000 );
//myField2.EnterText( b, 3000 );

2.After commenting those lines I want to copy them and change the calls in the following way:

myField1.Value = a;

So eventually I want to have something like this:

//myField1.EnterText( a, 1000 );
myField1.Value = a;
//myField2.EnterText( b, 3000 );
myField2.Value = b;

1 Answer 1

1

Try this

Find what:

{{.*\.}EnterText\({[^,]+}.*}

Replace with

//\1\n\2Value = \3

In Visual Studio you have to use {} to create a capturing group, means: you can reuse the matched parts inside those brackets using backreferences. \1 refers to the first opening bracket, \2 to the second, ...

[^,]+ is a negated character class that matches at least on character that is not a comma after the bracket of the method.

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

1 Comment

Thanks a lot! That was the trick to use curly brackets instead of normal brackets in Visual Studio!

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.