正则表达式或记事本+
我想找到在记事本中所有的下列情况++正则表达式或记事本+
action421
action732
action983
但忽略所有其他actionXXX
组合。
我正在寻找一个类似于action(421)|(732)|(983)
的正则表达式,但它不起作用。什么正则表达式会?
是否notepad++ regex engine甚至有一个OR
运算符?
看起来像Don Ho添加了RegEx或|运算符记入Notepad ++本机Find
,
最新版本的记事本(ver。6.1.1)。
下载记事本6.1.1从here
安装记事本6.1.1,然后去 搜索 - >查找
查找内容:action(421|732|983)
搜索模式:(*) Regular Expression
点击Find Next
按钮
完整的正则表达式是我在6.0中添加的。它经历了几轮改进和其他贡献(主要是F.R. Boyer),并且在6.3.1中非常稳定,可靠并且您期望得到。 – 2013-03-21 21:13:25
现在可以在Notepad> = 10.1.1中使用。据Dragos Toader:“最新版本今日(记事本10.1.1)支持|在正则表达式”
==原来答案在下面==
这是不可能在记事本++。 See this answer.
但是你的正则表达式是不正确的。如果Notepad ++在正则表达式中支持|
,这个工作将会起作用:action(421|732|983)
。
你的正则表达式似乎是正确的。但尝试使用此:
action(421|732|983)
它不起作用 - 我认为可以找到类似action4273283和action4213983的组合...... – Jonathan 2011-05-07 18:32:20
记事本++ doesn't support交替操作|
。 你可以尝试textfx ctrl + R regexp选项,但我认为同样如此。
正确的关于Scintilla RegEx功能是Notepad ++的核心。但是,Notepad ++行为可以使用插件进行修改。只搜索或搜索和替换操作可以重定向到外部插件库函数。 Notepad ++ PythonScript插件支持Python正则表达式搜索以及搜索和替换操作。请参阅下面的答案。 – 2012-04-20 20:00:53
今天的最新版本(记事本10.1.1)支持|在正则表达式 – 2012-04-20 22:54:28
使用PythonScript记事本+ +插件Python的正则表达式搜索功能。
的功能
Editor.pysearch(expression, function[, flags[, startLine[, endLine]]])
或
Editor.pymlsearch(expression, function[, flags[, startPosition[, endPosition]]])
下面是使用Python正则表达式搜索功能editor.pysearch()
我留下很多的调试代码,所以你一个简单的程序见here可以看到在功能运行过程中发生了什么。
# $Revision: 1.3 $
# $Author: dot $
# $Date: 2012/04/19 00:03:26 $
from Npp import *
import re, string
expression = notepad.prompt(
"Enter the RegEx search string then press Enter",
"RegEx and Search" ,
"")
debug = True
#debug = False
if debug:
bufferID = notepad.getCurrentBufferID()
if debug:
# Show console for debugging
console.clear()
console.show()
if expression != None:
expressionSansNl = expression.replace('\r\n', '')
if debug:
console.write(expression + "\n")
# First we'll start an undo action, then Ctrl-Z will undo the actions of the whole script
editor.beginUndoAction()
if debug:
console.write('editor.pysearch(r"%s" % expressionSansNl, None)\n')
editor.pysearch(r"%s" % expressionSansNl, None)
# End the undo action, so Ctrl-Z will undo the above two actions
editor.endUndoAction()
# Debug
if debug:
notepad.activateBufferID(bufferID)
将此脚本映射到Notepad ++快捷方式Ctrl+<ChooseALetter>
并运行它。
在搜索中输入正则表达式action(421|732|983)
根据Python re文档here,支持|
RegEx运算符。
我还没有测试过 - 也许pysearch()函数中的None参数需要
是一个函数,它将选择结果字符串。根据文档here,
函数应该返回一个python的MatchObject。我认为有一种方法可以从匹配对象中获取匹配字符串的
,并选择编辑器对象中匹配
字符串的下一个外观。一旦完成编码
并测试它,我会发布一个新的答案修订版。
这个答案适用于10.1.1之前的Notepad ++版本。在Notepad ++中,RegEx或|操作员可用。 – 2012-04-20 22:52:54
10.1.1版本的记事本++正则表达式引擎有一个OR操作符。 – 2012-04-20 23:27:08