正则表达式以查找字符串和更多内容 [英] Regex to find a string of characters + more
本文介绍了正则表达式以查找字符串和更多内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好
我正在寻找能找到一个字符串的正则表达式...
Hey all
I''m looking for a regular expression that will find a string of characters...
"/* Call SUT */"
然后假设在字符串之前插入3个换行符.
在第一个换行符上插入一个字符串...
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.
推荐答案
您无需使用正则表达式即可:只需使用string.Replace方法即可:
You don''t need a Regex to do that: you can just use the string.Replace method:
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 */");
设法自己解决问题.
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 */");
"); 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 \*\/.*
这篇关于正则表达式以查找字符串和更多内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文