简体   繁体   English

正则表达式在Notepad ++中不起作用

[英]Regular Expression Not Working in Notepad++

I am doing a Find & Replace in Notepad++. 我正在使用记事本++查找和替换。 Each of the pieces work correctly, but when I put the entire string together, it is not working. 每个部分都可以正常工作,但是当我将整个字符串放在一起时,它就无法工作。

I have an old HTML document I am editing where the original page cut up the text, thus: 我有一个旧的HTML文档,我正在编辑原始页面的文本,因此:

<div>
    <h2>Title</h2>
    <p>This is a line of[CR][LF]
    text that was cut to[CR][LF]
    fit on screen.</p>
</div>

I want to find the line breaks that are cutting up the text and eliminate them, but not other line breaks. 我想找到分割文本并消除它们的换行符,但不寻找其他换行符。

My regular expression is: 我的正则表达式是:

([A-z0-9]+)[\r\n][ ]{3,}([A-z0-9]+)

It will be replaced with: 它将被替换为:

$1 $2

I have tried each of the pieces of my regular expression and they all find what I would expect: ([A-z0-9]+) finds text, [\\r\\n] is finding my line breaks, [ ]{3,} is finding their initial indents, and ([A-z0-9]+) again finds text. 我已经尝试了正则表达式的每个部分,它们都找到了我期望的结果: ([A-z0-9]+)查找文本, [\\r\\n]查找我的换行符, [ ]{3,}正在找到其初始缩进,然后([A-z0-9]+)再次找到了文本。

I have even tried sets of expressions and they all work: ([A-z0-9]+)[\\r\\n] is finding text at the end of a line, [\\r\\n][ ]{3,} is finding line breaks with the indent at the beginning of the new line, and [ ]{3,}([A-z0-9]+) is finding initial indents followed by text. 我什至尝试了一组表达式,它们都起作用: ([A-z0-9]+)[\\r\\n]在一行的末尾查找文本, [\\r\\n][ ]{3,}在新行的开头找到带有缩进的换行符,而[ ]{3,}([A-z0-9]+)在找到初始缩进后跟文本。

Perhaps I have two questions: 1) Is this a Notepad++ bug, or have I missed something with my regular expression? 也许我有两个问题:1)这是Notepad ++错误,还是我正则表达式缺少某些内容? 2) Any ideas on solving this by some other expression? 2)关于通过其他表达方式解决此问题的想法?

If it is a bug, I suppose I can just trial and error until something works. 如果这是一个错误,我想我可以反复尝试直到可行。 It would probably be well to report the bug, though, so if anyone can verify that, it would help. 但是,报告该错误可能会很好,因此,如果任何人都可以验证这一点,将会有所帮助。

Your regex: 您的正则表达式:

([A-z0-9]+)[\r\n][ ]{3,}([A-z0-9]+)

matches one of \\r OR \\n . 匹配\\r\\n

Use this: 用这个:

([A-Za-z0-9]+)[\r\n]+[ ]{3,}([A-Za-z0-9]+)

or 要么

([A-Za-z0-9]+)\R+[ ]{3,}([A-Za-z0-9]+)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM