簡體   English   中英

Notepad++ 正則表達式搜索和替換忽略我的結果組

[英]Notepad++ regex search and replace ignores my result groups

我需要將幾個帶有問題的文本文件更改為在線學習平台使用的格式。

我有這種結構的線條:
\item Question in german.//Question in english.\\ %true
\item Second question in german.//Second question in english.\\ %false

我需要更改該行,使其看起來像這樣:
::Question in german.//Question in english.::[html]<p><span style\="font-size\: 14px;">Question in german.//Question in english.</span><br></p>{ %true
::Second question in german.//Second question in english..::[html]<p><span style\="font-size\: 14px;">Second question in german.//Second question in english.</span><br></p>{ %false

只有文本“德語問題。//英語問題。” 並且分析器 '%true' 發生變化(答案可以是真或假)。

我能夠用這個正則表達式找到我想要的部分:
(\\item )(.*)(\\\\ %.*)

我用這個
::\2::[html]<p><span style\="font-size\: 14px;">\2</span><br></p>{ \3
作為替換語句,但 Notepad++ 結果是:

 ::::[html]<p><span style="font-size: 14px;"></span><br></p>{ 

我也試過

:: $2 ::[html]<p><span style\="font-size\: 14px;"> $2 </span><br></p>{ $3

因為我不確定語法記事本++ v7.7 使用什么。 結果是相似的

 ::  ::[html]<p><span style="font-size: 14px;">  </span><br></p>{ 

我不知道為什么 Notepad++ 會忽略我的組。

解決方案

我無法用 Notepad++ 解決問題。 這是對我有用的解決方案:

我使用此網頁https://regex101.com/與模式搜索:
^\\item\h+(\N*?)//(\N*)\\\\\h*(\S+)

和替代品
::$1//$2::[html]<p><span style\="font-size\: 14px;">$1//$2</span><br></p>{ $3

在正則表達式模式下嘗試以下查找和替換:

Find:    ^\\\S+\s+(.*?)//(.*?)\\\\ %true$
Replace: ::$1//$2::[html]<p><span style\="font-size\: 14px;">$1//$2</span><br></p>{ %true

演示

您當前的模式不夠具體,而且(.*)捕獲組可能跨行匹配不正確,具體取決於所使用的正則表達式模式。

我無法用 Notepad++ 解決問題。 這是對我有用的解決方案:

我使用此網頁https://regex101.com/與模式搜索:
^\\item\h+(\N*?)//(\N*)\\\\\h*(\S+)

和替代品
::$1//$2::[html]<p><span style\="font-size\: 14px;">$1//$2</span><br></p>{ $3

這是解決方案DEMO的鏈接
歸功於 bobblebubble 和 TimBiegeleisen

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM