notepad4 icon indicating copy to clipboard operation
notepad4 copied to clipboard

正则表达式,跟其他软件正则表达式不匹配,无法匹配空行

Open yakoye opened this issue 8 months ago • 13 comments

在notepad4中,查找:^\s*$\n,无法查找到,能够把正则表达式引擎跟其他软件语法规则匹配?

notepad4 无任何匹配: Image

sublime text 可以匹配到:

Image

vscode可以匹配到:

Image

yakoye avatar Apr 28 '25 12:04 yakoye

查找:^\s*$\r\n ,可以匹配到 Image

yakoye avatar Apr 28 '25 12:04 yakoye

查找^\s*$的时候,只能匹配一次,其他软件可以把所有的都匹配到。

yakoye avatar Apr 28 '25 12:04 yakoye

Related issues: #804, #925.

zufuliu avatar May 01 '25 22:05 zufuliu

此项目默认的release是从原版notepad2开始就一直是目前这样的老引擎。

换 Boost regex 引擎的版本就可以用上和其他软件一致的语法了,但是我不知道哪里有release,只有去 Actions 里面才能下到

Mapaler avatar May 11 '25 16:05 Mapaler

但是我不知道哪里有release

https://github.com/zufuliu/notepad4/releases

Image

zufuliu avatar May 12 '25 13:05 zufuliu

但是我不知道哪里有release

https://github.com/zufuliu/notepad4/releases

Image

zufuliu avatar May 12 '25 13:05 zufuliu

但是我不知道哪里有release

https://github.com/zufuliu/notepad4/releases

Image

谢谢,我的意思是不知道哪里有 Boost regex 版本的 release。 我之前的印象是release里还是老引擎,要 actions 切到 boost 分支下的才是 boost 引擎。 目前发现这个分支已经不见了,新的 release 已经可以通过打勾来切换引擎了。

Mapaler avatar May 12 '25 13:05 Mapaler

在notepad4用正则(\S+) (\S+)搜索:uzbk 手柄 后,使用:$2 $1 替换前后顺序时,替换结果是:$2 $1,而不是: 手柄 uzbk 用NOTEPAD2也是同样的结果,不知道什么时候才能搞定正则替换问题,大概得更换其他的正则引擎吧……

lidawei97688 avatar Nov 16 '25 09:11 lidawei97688

使用:$2 $1 替换前后顺序时

Use \1 and \n.

Image

zufuliu avatar Nov 16 '25 10:11 zufuliu

使用:$2 $1 替换前后顺序时

Use \1 and \n. Image

根据您的回答
https://github.com/zufuliu/notepad4/issues/1104#issuecomment-3440274055 可以看到 Boost 引擎的语法和其他软件一样是 $n
https://www.boost.org/doc/libs/latest/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html 如果有可能,废弃老的引擎,使用单纯的 Boost 引擎,以保持和其他现代文本编辑器的操作模式一致。

Mapaler avatar Nov 16 '25 21:11 Mapaler

可以看到 Boost 引擎的语法和其他软件一样是 $n

https://www.boost.org/doc/libs/latest/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html#boost_regex.format.boost_format_syntax.placeholder_sequences https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_the_replacement

Support $$ (literal $), $& (whole matched text, same as $0) and $n only needs small change to BuiltinRegex::SubstituteByPosition(). I think here is no need to support $` (text before the match) and $' (text after the match), sine we match on whole line or document.

zufuliu avatar Nov 17 '25 10:11 zufuliu

Image

我认为这些开关应该梳理一遍,现在的排序逻辑很混乱。

不用的就去掉,再根据“通用”、“普通替换”、“正则替换”用 frame 或 tab 分类。

这是我做的一个概念。第一行两个功能选项,点到查找时直接禁用替换相关控件就可以了,这样界面就不用变来变去。 Image

也可以像Notepad--一样,把

  • 替换后关闭
  • 使用等宽字体
  • 离开对话框后进入透明模式

等内容做到独立的一个设置面板,减少主界面的内容。

Image

Mapaler avatar Nov 18 '25 03:11 Mapaler

Commit f5397a21ad1a5f0c3a96ebff65b5c84440a1b74d implemented regex replace with $n, $& and $$ for both engines.

zufuliu avatar Nov 19 '25 11:11 zufuliu