我想找到在記事本中所有的下列情況++正則表達式或記事本+
action421
action732
action983
但忽略所有其他actionXXX
組合。
我正在尋找一個類似於action(421)|(732)|(983)
的正則表達式,但它不起作用。什麼正則表達式會?
是否notepad++ regex engine甚至有一個OR
運算符?
我想找到在記事本中所有的下列情況++正則表達式或記事本+
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
對於Notepad ++,您可以使用regex helper plugin,但這對於正則表達式開發來說比replace更重要,但是如果您只是想查找,我認爲這個插件可能會有所幫助。
使用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