Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey all

I'm looking for a regular expression that will find a string of characters...

"/* Call SUT */"

It is then suppose to insert 3 newlines before the string of characters.

On the First newline insert a string...

"/* Lower LOG level to improve performance and decrease output file size. */"


On the Second newline insert a string...

"Old_Log_Level = SET_LOG_LEVEL(cppth_ll_concise);"


And leave the Third newline empty.

Final result should look like:
/* Lower LOG level to improve performance and decrease output file size. */
Old_Log_Level = SET_LOG_LEVEL(cppth_ll_concise);

/* Call SUT */


Help would be appreciated.
Posted
Updated 7-Feb-11 22:27pm
v3
Comments
Umair Feroze 8-Feb-11 4:39am    
Is there any specific reason to use the Regular expression. It can also be done with replace function. You can search for newline+"/* Call SUT */"+newline and replace it with the lines you want i.e. /* Lower LOG level to improve performance and decrease output file size. */Old_Log_Level = SET_LOG_LEVEL(cppth_ll_concise);/* Call SUT */
R. Erasmus 8-Feb-11 4:42am    
yes there is a specific reason... I'm using textpads regular expression find/replace mechanism... I found the solution in any case, thx.

You don't need a Regex to do that: you can just use the string.Replace method:
C#
string inp = "hello there\n/* Call SUT */goodbye";
inp = inp.Replace("/* Call SUT */",
                  "/* Lower LOG level to improve performance and decrease output file size. */\n" +
                  "Old_Log_Level = SET_LOG_LEVEL(cppth_ll_concise);\n" +
                  "\n" +
                  "/* Call SUT */");
 
Share this answer
 
Comments
Espen Harlinn 20-Feb-11 10:17am    
Nice and simple :)
Managed to solve the problem myself thx.

Regex("^.*\/\* Call SUT \*\/.*$");
Regex("        \/\* Lower LOG level to improve performance and decrease output file size\. \*\/\n        Old_Log_Level = SET_LOG_LEVEL(cppth_ll_concise);\n\n        /* Call SUT */");


Or what I actually wanted to use it for:
Find what:
^.*\/\* Call SUT \*\/.*$
Replace with:
\/\* Lower LOG level to improve performance and decrease output file size\. \*\/\n        Old_Log_Level = SET_LOG_LEVEL(cppth_ll_concise);\n\n        /* Call SUT */
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900