2011-05-07 115 views
28

我想找到在記事本中所有的下列情況++正則表達式或記事本+

action421 
action732 
action983 

但忽略所有其他actionXXX組合。

我正在尋找一個類似於action(421)|(732)|(983)的正則表達式,但它不起作用。什麼正則表達式會?

是否notepad++ regex engine甚至有一個OR運算符?

+3

10.1.1版本的記事本++正則表達式引擎有一個OR操作符。 – 2012-04-20 23:27:08

回答

34

看起來像Don Ho添加了RegEx或|運算符記入Notepad ++本機Find,
最新版本的記事本(ver。6.1.1)。
下載記事本6.1.1從here

安裝記事本6.1.1,然後去 搜索 - >查找
查找內容:action(421|732|983)
搜索模式:(*) Regular Expression

點擊Find Next按鈕

+1

完整的正則表達式是我在6.0中添加的。它經歷了幾輪改進和其他貢獻(主要是F.R. Boyer),並且在6.3.1中非常穩定,可靠並且您期望得到。 – 2013-03-21 21:13:25

8

現在可以在Notepad> = 10.1.1中使用。Dragos Toader:「最新版本今日(記事本10.1.1)支持|在正則表達式」

==原來答案在下面==

這是不可能在記事本++。 See this answer.

但是你的正則表達式是不正確的。如果Notepad ++在正則表達式中支持|,這個工作將會起作用:action(421|732|983)

+0

嗯...這似乎不工作!?不管在我的記事本++中...... **編輯** @Jonathan爲你做這個工作? – Rudie 2011-05-07 18:30:22

+0

它不起作用 - 我認爲可以找到類似action4273283和action4213983的組合...... – Jonathan 2011-05-07 18:32:14

+0

沒有'('和')'表示一個組。 '|'的意思是「或」。在PHP中,這個正則表達式很完美。在Notepad ++中,我無法使它工作。我已經用PHP中的一個例子更新了答案。 – Rudie 2011-05-07 18:33:34

0

你的正則表達式似乎是正確的。但嘗試使用此:

action(421|732|983) 
+0

它不起作用 - 我認爲可以找到類似action4273283和action4213983的組合...... – Jonathan 2011-05-07 18:32:20

1

記事本++ doesn't support交替操作|。 你可以嘗試textfx ctrl + R regexp選項,但我認爲同樣如此。

+0

正確的關於Scintilla RegEx功能是Notepad ++的核心。但是,Notepad ++行爲可以使用插件進行修改。只搜索或搜索和替換操作可以重定向到外部插件庫函數。 Notepad ++ PythonScript插件支持Python正則表達式搜索以及搜索和替換操作。請參閱下面的答案。 – 2012-04-20 20:00:53

+0

今天的最新版本(記事本10.1.1)支持|在正則表達式 – 2012-04-20 22:54:28

7

對於Notepad ++,您可以使用regex helper plugin,但這對於正則表達式開發來說比replace更重要,但是如果您只是想查找,我認爲這個插件可能會有所幫助。

enter image description here

+0

謝謝,但我真的需要功能,如「找到所有當前文件」和「計數」記事本++有... – Jonathan 2011-05-07 21:54:43

+1

@Jonathan你會得到所有和計數。看截圖。它突出顯示所有內容,並在窗口右下角顯示計數。 – manojlds 2011-05-07 22:04:24

+0

你是對的,我仍然發現Regex Helper是一個有限的工具 – Jonathan 2011-05-17 06:25:57

1

使用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。我認爲有一種方法可以從匹配對象中獲取匹配字符串的
,並選擇編輯器對象中匹配
字符串的下一個外觀。一旦完成編碼
並測試它,我會發佈一個新的答案修訂版。

+0

這個答案適用於10.1.1之前的Notepad ++版本。在Notepad ++中,RegEx或|操作員可用。 – 2012-04-20 22:52:54