我想在Notepad++中查找所有以下实例
action421
action732
action983
但忽略所有其他 actionXXX
的组合。
我正在寻找一种类似于 action(421)|(732)|(983)
的正则表达式,但它不起作用。有什么正则表达式可以使用吗?
Notepad++ 的正则表达式引擎 是否甚至有一个 OR
运算符?
我想在Notepad++中查找所有以下实例
action421
action732
action983
但忽略所有其他 actionXXX
的组合。
我正在寻找一种类似于 action(421)|(732)|(983)
的正则表达式,但它不起作用。有什么正则表达式可以使用吗?
Notepad++ 的正则表达式引擎 是否甚至有一个 OR
运算符?
看起来Don Ho在最新版本的Notepad(ver. 6.1.1)中添加了正则表达式OR |运算符到Notepad++本地查找
功能。
从这里下载Notepad 6.1.1
安装Notepad 6.1.1,然后转到
搜索->查找
查找内容:action(421|732|983)
搜索模式:(*) 正则表达式
单击查找下一个
按钮
现在在Notepad>=10.1.1版本中可以实现。根据Dragos Toader的说法:“截至今天最新版本(Notepad 10.1.1)支持正则表达式中的|”
== 原始答案如下 ==
在Notepad++中不可能。看看这个答案。
但是你的正则表达式不正确。如果Notepad++支持正则表达式中的|
,那么这个正则表达式将会起作用:action(421|732|983)
。
(
和 )
表示一组。|
表示 OR
。在 PHP 中,这个正则表达式完美地工作。在 Notepad++ 中,我无法让它工作。我已经更新了一个在 PHP 中工作的例子。 - Rudie|
。您可以尝试使用textfx ctrl+R正则表达式选项,但我认为结果是一样的。Editor.pysearch(expression, function[, flags[, startLine[, endLine]]])
或者
Editor.pymlsearch(expression, function[, flags[, startPosition[, endPosition]]])
# $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,支持|
正则表达式操作符。
我还没有测试过这个--也许pysearch()函数中的None参数需要
是一个选择结果字符串的函数。根据文档here,
该函数应返回一个python MatchObject。我认为有一种方法可以从MatchObject中获取匹配字符串,并选择编辑器对象中下一个出现的匹配字符串。完成编码和测试后,我将发布答案的新版本。
你的正则表达式似乎是正确的。但尝试使用这个:
action(421|732|983)