monk Sarana
monk Sarana

Reputation: 11

matching first occurrence of a symbol without anything else in EditPad

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?

Upvotes: 1

Views: 183

Answers (2)

The fourth bird
The fourth bird

Reputation: 163362

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

Upvotes: 1

zx81
zx81

Reputation: 41838

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

Upvotes: 1

Related Questions