Search code examples
regexnotepad++

Bookmark last comma-separated value before specific separator using Notepad++ regex


I have a list of text data formatted as follows:

Drtyjtyjnt
11,825,222
Ftyryer
8,823,623
Strtrtuperd
8,542,448
Ts
7,153,156
Supd
7,122,304
Su.3
6,920,743
Supld
dddd
tgtgtg
Sd
April 1991
/////////////////////////
Freeeer
7,537,583
Dufdgnt
4,381,322
SioBup
3,010,937
S
2,238,608
Du
SuperM
Sup
August 1989
/////////////////////////
D
12,184,781
S
9,023,965
Fog
8,913,781
Supe
7,441,191
May 1991
/////////////////////////

I want to bookmark the last comma-separated value before each ///////////////////////// separator using Notepad++ regex. For example, in the list provided, the following lines should be bookmarked:

6,920,743
2,238,608
7,441,191

I have attempted to use the following regex patterns but they did not work:

(?-s)(\d{1,3}(?:,\d{3})+)(?=(?:(?!\R/////////////////////////).)*\R/////////////////////////)
(?s)(\d{1,3}(?:,\d{3})+)(?=(?:\R(?!/////////////////////////).)*\R/////////////////////////)

Could someone help identify what might be wrong with these regex patterns or provide a working solution?


Solution

  • You can use

    ^\d+(?:,\d+)*$(?=(?:\R(?!\d+(?:,\d+)*$).*)*\R/{3,}$)
    

    See the regex demo

    Details

    • ^ - start of a line
    • \d+(?:,\d+)* - two or more comma-separated digit sequences
    • $ - end of a line
    • (?=(?:\R(?!\d+(?:,\d+)*$).*)*\R/{3,}$) - a positive lookahead that requires (immediately to the right of the current location):
      • (?:\R(?!\d+(?:,\d+)*$).*)* - zero or more occurrences of
        • \R(?!\d+(?:,\d+)*$) - a line break not followed by a line that only contains comma-separated digit sequences
        • .* - the rest of the line
      • \R - a line break
      • /{3,} - three or more / chars
      • $ - end of a line

    NPP test:

    enter image description here