我想在notepad ++中找到以下所有实例
action421
action732
action983
但忽略所有其他actionXXX
组合。
我正在寻找类似于action(421)|(732)|(983)
的正则表达式,但它不起作用。什么是正则表达式?
notepad++ regex engine是否还有OR
运算符?
答案 0 :(得分:35)
看起来Don Ho添加了RegEx OR |操作符到本机中的Notepad ++ native Find
最新版本的记事本(版本6.1.1)
从here
安装Notepad 6.1.1,然后转到
搜索 - >查找
找到:action(421|732|983)
搜索模式:(*) Regular Expression
点击Find Next
按钮
答案 1 :(得分:8)
现在可以在记事本&gt; = 10.1.1。根据Dragos Toader:“截至今日的最新版本(记事本10.1.1)支持|在RegEx中”< / p>
==以下原始答案==
在Notepad ++中无法实现。 See this answer.
但你的正则表达不正确。如果Notepad ++支持正则表达式中的action(421|732|983)
,则可以使用|
。
答案 2 :(得分:6)
您可以将regex helper plugin用于Notepad ++,但对于正则表达式开发而言,这比替换更多,但如果您只想查找,我认为此插件可能会有所帮助。
答案 3 :(得分:1)
Notepad ++ doesn't support交替运算符|
。
您可以尝试使用textfx ctrl + R regexp选项,但我认为情况也是如此。
答案 4 :(得分:1)
使用PythonScript Notepad ++插件进行Python正则表达式搜索功能 有关功能
,请参阅hereEditor.pysearch(expression, function[, flags[, startLine[, endLine]]])
或
Editor.pymlsearch(expression, function[, flags[, startPosition[, endPosition]]])
这是一个使用python正则表达式搜索函数editor.pysearch()的简单程序 我已经留下了很多调试代码,因此你可以看到在函数运行过程中发生了什么。
# $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>
并运行它
输入搜索RegEx action(421|732|983)
根据Python重新文档here,支持|
RegEx运算符。
我没有测试过这个 - 也许pysearch()函数中的None参数需要
是一个将选择结果字符串的函数。根据文档here,
该函数应该返回一个python MatchObject。我认为有办法获得
匹配MatchObject中的字符串并选择匹配的下一个外观
编辑器对象中的字符串。一旦我完成编码,我会发布一个新的答案修订版
并测试这个。
答案 5 :(得分:0)
你的正则表达式似乎是正确的。但试着用这个:
action(421|732|983)