Search code examples
notepad++

Bookmark consecutive lines that start with a number


I want to bookmark consecutive lines that start with a number in Notepad++ with regex
for example, if my list is the following:

ABC
1,234,543
DFGHH
1234
HRHYTTJ
JTJYMYUY
1,456
23,567
hhtyjtyj
43,679
1969Q3

I need a regex that bookmarks the following in the above list:

1,456
23,567

The following regex works well:

^\d+.*\R(\d+.*)$

but it has a problem, it bookmark quarter lines in my list too! and I don't like this.
I tried the following regex but it is not working:

^(?!\d{4}Q[1-4])[^\d+.*\R(\d+.*)$]+

where is the problem?


Solution

  • With your shown samples and attempts please try following regex.

    (?:^|\R)\K\d+(?:,\d+)*\R\d+(?:,\d+)*(?=\R)
    

    Explanation: Adding detailed explanation for above regex.

    (?:^|\R)         ## In a non-capturing group matching starting of a line OR \R here.
    \K               ## \K is used to make sure previous match is done by don't consider it while printing/highlighting values.
    \d+(?:,\d+)*\R   ## Matching 1 or more digits following by an optional non-capturing group which has comma followed by digits; then non-capturing group is followed by \R.
    \d+(?:,\d+)*     ## Matching 1 or more digits following by an optional non-capturing group which has comma followed by digits
    (?=\R)           ## Using positive look ahead to check if its followed by \R.