我想用反斜杠代替斜杠里面的#包括双引号,像这样。
先于
#include "Monster.h"
#include "ItemManager.h"
#include "Skil/Server/Manager/Skillmanager.h"
#include "Quest/QuestEvent.h"
#include "AES/AES.h"
#include "Trigger/Timer.h"
// Timer Class
CTimer::CTimer()
{
printf("Minute / Second");
printf("\t%2d:%2d\n", tMinute, tSecond);
}后
#include "Monster.h"
#include "ItemManager.h"
#include "Skil\Server\Manager\Skillmanager.h"
#include "Quest\QuestEvent.h"
#include "AES\AES.h"
#include "Trigger\Timer.h"
// Timer Class
CTimer::CTimer()
{
printf("Minute / Second");
printf("\t%2d:%2d\n", tMinute, tSecond);
}我希望只在#include标记中替换斜杠,而不是替换printf标记和注释标记中的斜杠。
我用来搜索的正则表达式是什么?
谢谢你。
发布于 2014-05-31 11:32:09
您的代码在C++中,但您还没有说明如何替换斜杠:这可能是在IDE中、使用脚本或使用其他工具。
下面是使用regex模式下的搜索和替换来工作Notepad++ (测试)的解决方案。
搜索:(?m)(?:^#include\s*"|\G)[^/"]*\K/
替换:\
解释:
(?m)(?:^#include\s*"|\G)[^/"]*\K/(?m) m在换行处的匹配
(?:^#include\s*"|\G) 下面的正则表达式^#include\s*" ^ )#include\s* *
- Match the character “"” literally `"`
- Or match this alternative (the entire group fails if this one fails to match) `\G`
- Assert position at the end of the previous match (the start of the string for the first attempt) `\G`
[^/"]* 中不存在的任何单个字符*
\K保持很远的匹配/https://stackoverflow.com/questions/23968429
复制相似问题