1

There is a question like this here asking about the first occurrence of "1" in each line, but in EditPad it doesn't work at all, even when I use the Multi-Line Search Panel.

I have Regex on, Highlight All on. All other functions are off.

  1. /^[^1\n\r]*(1)/m - highlights nothing
  2. ^[^1\n\r]*(1)/m - highlights nothing
  3. ^[^1\n\r]*(1) - finds all lines that contain "1" and highlights everything from the start of the line until the number "1". But I need only the first occurrence of "1", nothing else.

I guess that ^[^1\n\r]*(1) is one step towards the real "first occurrence", but it is not there yet.

For example, I have the number 5215681571

And I want to highlight only the first "1" in the line. The expression ^[^1\n\r]*(1) will highlight 521 which is not desirable.

I have tried also ^(^.*[^1])1 which finds every line that contains 1 and highlights everything from start until the last "1".

In stackoverflow, I have seen countless suggestions on how to achieve the first occurrence, but none of them works in EditPad. Any idea, please?

4

2 回答 2

0

在您尝试的模式中,您使用捕获组,前面有一个匹配项。

如果这是正则表达式引擎所支持的工具indicated as JGsoft V2,它支持使用\K来忘记迄今为止匹配的内容。

匹配除 1 或回车符或换行符之外的所有内容:

^[^\r\n1]*\K1

正则表达式演示

或匹配除 1 和垂直空格之外的所有字符\v

^[^\v1]*\K1

正则表达式演示

于 2021-08-02T07:24:10.270 回答
0

除了@The Fourth Bird 的建议之外,EditPad 的 JGSoft 引擎还支持无限后视,这让您可以做到这一点(在 EPP Pro 8.2.4 中测试):

(?<=^[^1\r\n]*)1

要捕获任何奇怪的 unicode 换行符,您还可以使用[^\p{Zl}]代替[^\r\n],产生以下两个替代版本:

^[^\p{Zl}1]*\K1

或者

(?<=^[^1\p{Zl}]*)1
于 2021-08-02T09:07:02.727 回答