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?

  • Not sure which [regex flavour](https://en.wikipedia.org/wiki/Comparison_of_regular-expression_engines#Language_features) does EditPad use. If it's PCRE, [`^.*?\K1`](https://regex101.com/r/unV87Z/1/) would do the trick. – Hao Wu Aug 02 '21 at 01:02

2 Answers2

1

In the patterns that you tried, you use a capture group, preceded by a match.

If this is the tool the regex engine is indicated as JGsoft V2 which supports using \K to forget what is matched so far.

Matching all except 1 or a carriage return or a newline:

^[^\r\n1]*\K1

Regex demo

Or matching all except 1 and vertical whitespaces \v

^[^\v1]*\K1

Regex demo

The fourth bird
  • 154,723
  • 16
  • 55
  • 70
1

In addition to what @The fourth bird suggested, EditPad's JGSoft engine supports infinite lookbehind, which lets you do this (tested in EPP Pro 8.2.4):

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

To catch any kind of weird unicode line breaks you can also use [^\p{Zl}] in place of [^\r\n], yielding these two alternate versions:

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

or

(?<=^[^1\p{Zl}]*)1
zx81
  • 41,100
  • 9
  • 89
  • 105