1

I'm trying to find all var.AppendLine("..."); and replace them with Append("...\n");

Been fooling around with regex's but don't seem to get anywhere. Anyone has a suggestion on what regular expression to use here?

var can be a variable name and I need to select the ... for replace with Append("$1\n");

8
  • What regex did you tried? How does it behaves? Commented Jan 17, 2013 at 9:04
  • Well i googled a bit, but don't seem to have found anything that has results... Flying blind. Commented Jan 17, 2013 at 9:04
  • Regex.Replace(str, @"...", "...\n"); Commented Jan 17, 2013 at 9:06
  • Its for the Visual Studio find and replace functionality Commented Jan 17, 2013 at 9:07
  • Sounds a bit dangerous... how confident are you there are no "); WITHIN the text anywhere in the code? Commented Jan 17, 2013 at 9:09

2 Answers 2

1

I assume you actually don't want to get rid of var:

Search: <{[a-zA-Z0-9]+}.AppendLine\("{[^"]+}"\)

Replace with: \1.Append("\2\\n")

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

7 Comments

Thanks Chris, almost there... I've used this now: (VS 2012): ([a-zA-Z0-9]+).AppendLine\("([^"]+)"\) however, it selects sb.AppendLine.. and then b.AppendLine.. again...
@Ferdy: Fixed, need to match on word start
Adding the < breaks the regex for me. Has something to do with the tabs / spaces infront of it?
@Ferdy: Works fine for me in VS2010
Using VS 2012, got it working, however... It adds \\n at the end of the Append. When i use \n it adds a new line. Any way of adding \n litterally?
|
1

I think you meand the regex in the "search& replace window of VS ? Then something like

<{[a-zA_Z]+\.}{AppendLine\("}{[^"]+}{"\)}

to replace with

\1Append("\3\\n")

(remove the \1 if you want to remove the "var." part, not clear in your question)

2 Comments

TIL that VS Replace uses curly braces, not brackets, for capture groups :-/
That looks like MSVS 2010 RE syntax, but the question is about MSVS 2012, which uses .NET RE syntax.

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.