[英]Notepad++ regex search and replace ignores my result groups
I need to change several text files with questions to a format which a online learning platform uses.我需要将几个带有问题的文本文件更改为在线学习平台使用的格式。
I have lines with this structure:我有这种结构的线条:
\item Question in german.//Question in english.\\ %true
\item Second question in german.//Second question in english.\\ %false
I need to change the line so it would look like this:我需要更改该行,使其看起来像这样:
::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
Only the text 'Question in german.//Question in english.'只有文本“德语问题。//英语问题。” and the anser '%true' changes (the answer can either be true or false).
并且分析器 '%true' 发生变化(答案可以是真或假)。
I was able to find my wanted part with this regex expression:我能够用这个正则表达式找到我想要的部分:
(\\item )(.*)(\\\\ %.*)
I used this我用这个
::\2::[html]<p><span style\="font-size\: 14px;">\2</span><br></p>{ \3
as replacement statement but Notepad++ result is:作为替换语句,但 Notepad++ 结果是:
::::[html]<p><span style="font-size: 14px;"></span><br></p>{
I also tried我也试过
:: $2 ::[html]<p><span style\="font-size\: 14px;"> $2 </span><br></p>{ $3
because I'm not sure what Syntax notepad++ v7.7 uses.因为我不确定语法记事本++ v7.7 使用什么。 The result is similar
结果是相似的
:: ::[html]<p><span style="font-size: 14px;"> </span><br></p>{
I have no idea why Notepad++ ignores my groups.我不知道为什么 Notepad++ 会忽略我的组。
SOLUTION解决方案
I wasn't able to solve the problem with Notepad++.我无法用 Notepad++ 解决问题。 Here is the solution that worked for me:
这是对我有用的解决方案:
I used this webpage https://regex101.com/ with the pattern to search:我使用此网页https://regex101.com/与模式搜索:
^\\item\h+(\N*?)//(\N*)\\\\\h*(\S+)
and for substitiution和替代品
::$1//$2::[html]<p><span style\="font-size\: 14px;">$1//$2</span><br></p>{ $3
Try the following find and replace, in regex mode:在正则表达式模式下尝试以下查找和替换:
Find: ^\\\S+\s+(.*?)//(.*?)\\\\ %true$
Replace: ::$1//$2::[html]<p><span style\="font-size\: 14px;">$1//$2</span><br></p>{ %true
Your current pattern is not specific enough, and also the (.*)
capture group might possibly match incorrectly across lines, depending on the regex mode being used.您当前的模式不够具体,而且
(.*)
捕获组可能跨行匹配不正确,具体取决于所使用的正则表达式模式。
I wasn't able to solve the problem with Notepad++.我无法用 Notepad++ 解决问题。 Here is the solution that worked for me:
这是对我有用的解决方案:
I used this webpage https://regex101.com/ with the pattern to search:我使用此网页https://regex101.com/与模式搜索:
^\\item\h+(\N*?)//(\N*)\\\\\h*(\S+)
and for substitiution和替代品
::$1//$2::[html]<p><span style\="font-size\: 14px;">$1//$2</span><br></p>{ $3
Here is the link to the solution DEMO这是解决方案DEMO的链接
Credit goes to bobblebubble and TimBiegeleisen归功于 bobblebubble 和 TimBiegeleisen
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.