
我已經對這個主題進行了一些研究,但我無法找到適合我的特殊需求的確切解決方案。我正在使用 Notepad++ 編寫一些 Z80 彙編程式碼。我需要將“:”字元的所有實例替換為“::”,但僅限於特定情況。例如,假設我的程式碼如下所示:
SomeFunction:
ld a, whatever
ret
; Remember to do this: blah blah blah
Function2:
jr z, someWhere
.subfunction:
ld hl, somePointer
ret
通常,我可以繼續執行Ctrl+H 將“:”的所有實例替換為“::”...但是,在這種特殊情況下,我想避免替換以“::”開頭的行上的單個“ :”字元帶有“.”或“;”。所有其他“:”實例,請將其變更為“::”。本質上,最終結果將如下所示:
SomeFunction::
ld a, whatever
ret
; Remember to do this: blah blah blah
Function2::
jr z, someWhere
.subfunction:
ld hl, somePointer
ret
我說得有道理嗎?我知道我可以(並且應該)為此使用正則表達式,並且會涉及通配符,但我不確定如何我會去格式化它。非常感謝!
答案1
答案2
這也可以檢查冒號是否已經加倍。
- Ctrl+H
- 找什麼:
^(?![;.]).*?(?<!:):\K(?!:)
- 用。
:
- 查看 環繞
- 查看 正規表示式
- 取消選取
. matches newline
- Replace all
解釋:
^ # beginning of line
(?![;.]) # negative lookahead, make sure the next character is not ; or .
.*? # 0 or more any character but newline, not greedy
(?<!:) # negative lookbehind, make sure the previous character is not :
: # a colon
\K # forget all we have seen until this position
(?!:) # negative lookahead, make sure the next character is not :
截圖(之前):
截圖(之後):