Notepad++ regex to get each unique number located between two recurring tags

Viewed 63

I have 16k lines of text in a file. Opening it with Notepad++

Every few lines there is an occurrence like this one:

a few rows of text before
    Unique Identifier
    628612012-078
    Title
another few rows of text until the next Unique Identifier row

a few more lines of something else then it repeats again with a different number in between

a few rows of text before
Unique Identifier
1991-18613-001
Title
another few rows of text until the next Unique Identifier row

Picture of data:

enter image description here

What would a regex look like to get (copy/save) each id number located between each Unique Identifier and Title tag/row?

I don't mind if it deletes the rest of the text in the file or saves the output as another file or whatever. Ideally, I need to have just a list of those numbers occurring, in order.

Tried this/to adapt this Find and copy text between { and } in Notepad++ - couldn't get it to work

2 Answers

if the file has Unix(LF) line endings, the regex is

(?<=Unique Identifier\n).+(?=\nTitle)

then use Mark All and Copy Marked Text to get all mathes into Clipboard enter image description here

Use

^Unique Identifier\R(\d+(?:-\d+)*)(?=\RTitle$)|^(?!Unique Identifier$).*\R?

Replace with: (?1$1\n:) - first capture group value with line feed or nothing.

EXPLANATION

--------------------------------------------------------------------------------
  ^                        the beginning of the line
--------------------------------------------------------------------------------
  Unique Identifier        'Unique Identifier'
--------------------------------------------------------------------------------
  \R                       any line ending sequence
--------------------------------------------------------------------------------
  (                        group and capture to \1:
--------------------------------------------------------------------------------
    \d+                      digits (0-9) (1 or more times (matching
                             the most amount possible))
--------------------------------------------------------------------------------
    (?:                      group, but do not capture (0 or more
                             times (matching the most amount
                             possible)):
--------------------------------------------------------------------------------
      -                        '-'
--------------------------------------------------------------------------------
      \d+                      digits (0-9) (1 or more times
                               (matching the most amount possible))
--------------------------------------------------------------------------------
    )*                       end of grouping
--------------------------------------------------------------------------------
  )                        end of \1
--------------------------------------------------------------------------------
  (?=                      look ahead to see if there is:
--------------------------------------------------------------------------------
    \R                       'R'
--------------------------------------------------------------------------------
    Title                    'Title'
--------------------------------------------------------------------------------
    $                        the end of the line
--------------------------------------------------------------------------------
  )                        end of look-ahead
--------------------------------------------------------------------------------
 |                        OR
--------------------------------------------------------------------------------
  ^                        the beginning of the line
--------------------------------------------------------------------------------
  (?!                      look ahead to see if there is not:
--------------------------------------------------------------------------------
    Unique Identifier        'Unique Identifier'
--------------------------------------------------------------------------------
    $                        the end of the line
--------------------------------------------------------------------------------
  )                        end of look-ahead
--------------------------------------------------------------------------------
  .*                       any character except \n (0 or more times
                           (matching the most amount possible))
--------------------------------------------------------------------------------
  \R?                      any line ending sequence (optional)
Related