2016-09-19 69 views
1

使用正则表达式查找和重排命令我试图找到这样的事情在记事本++

MakeVariable(magnet, "1", "Enable magnet") 

CVariable magnet("magnet", "1", "Enable magnet") 

这里取而代之的是什么,我试图

Find What: MakeVariable(([^ ]+), 

Replace with: CVariable \1 ("\1 ", 
+0

难道不该'MakeVariable \(([^] +),'?你也试试'\ g时,'(''中的<1>代替'\ 1'。 – Xufox

+0

其实替代模式也应该逃脱,因为NPP在括号具有特殊含义的情况下使用Boost风格的条件替换模式。 –

回答

1

您需要在搜索和替换模式中转义文字圆括号。

另外,如果你的第一个参数是字的一大块字符使用\w+与之相匹配的:

查找内容MakeVariable\(\s*(\w+)
替换CVariable $1\("$1"

详细

  • MakeVariable - MakeVariable文本
  • \( - 字面(
  • \s* - 零个或多个空格
  • (\w+) - 第1组匹配一个或多个单词字符

替代解决方案,你原来的模式更类似于一个MakeVariable\(\s*(\S+),正则表达式搜索和CVariable $1\("$1",模式替换(其中\w+被替换为\S+ - 一个或多个非空白符号)。

enter image description here