Skip to main content
dublove
Legend
June 4, 2025
Answered

Hi m1b, Can you explain (? :\r(? =\r)|$) what it means?

  • June 4, 2025
  • 1 reply
  • 173 views

@m1b 

It seems that not grouping is only one aspect.
It's meant to make the lookup hit an end point, but I'm still having trouble understanding it.


I found one that works better, with the addition of an extra \s*,it can contain multiple blank lines, where your original one could only contain one.
(? :\r\s*(? =\r)|($))

But I still can't fully understand it originally.

 

There's also this (? :^|(? <=\r)\r).

Correct answer m1b
(?:\r(?=\r)|$)

 

Firstly,

(?:  – starts a non-capturing group.

 

\r(?=\r)|$

This means match 1 carriage return when there is a carriage return after it, OR nothing at the end of a line.

 

(?:^|(?<=\r)\r)

This is the reverse of the first pattern: match nothing at the start of a line OR match 1 carriage return when there is a carriage return before it. 

1 reply

m1b
Community Expert
m1bCommunity ExpertCorrect answer
Community Expert
June 5, 2025
(?:\r(?=\r)|$)

 

Firstly,

(?:  – starts a non-capturing group.

 

\r(?=\r)|$

This means match 1 carriage return when there is a carriage return after it, OR nothing at the end of a line.

 

(?:^|(?<=\r)\r)

This is the reverse of the first pattern: match nothing at the start of a line OR match 1 carriage return when there is a carriage return before it. 

dublove
dubloveAuthor
Legend
June 5, 2025

Thank you.
Probably understand that it's a matter of figuring out how to make the main lookup structure, get a start and an end.