My preference would be to use two Capture Groups with one Search using Regular Expression action, since you probably want to use each Reference# separately.
==Assuming the Reference numbers are defined by a Regex Word==, then this Regex should work:
(?i)reference.+?(\w+).*\R.+?reference.+?(\w+)
For details, see regex101: build, test, and debug regex
If you want a broader definition of Reference number that must start with a RegEx word character, but then can be anything other than a SPACE, then this would work:
(?i)reference.+?(\w[^ ]+).*\R.+?reference.+?(\w[^ \n\r]+)
Below is just an example written in response to your request. You will need to use as an example and/or change to meet your workflow automation needs.
Example Output

NOTE: There may be minor errors in the source text, which was obtained by OCR of your image. In the future, please post your source text using a Forum Code Block.
Please let us know if it meets your needs.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
MACRO: Extract Reference Numbers from Multiline Sring [Example]
-~~~ VER: 1.0 2020-07-17 ~~~
Requires: KM 8.2.4+ macOS 10.11 (El Capitan)+
(Macro was written & tested using KM 9.0+ on macOS 10.14.5 (Mojave))
DOWNLOAD Macro File:
Extract Reference Numbers from Multiline Sring [Example].kmmacros
Note: This Macro was uploaded in a DISABLED state. You must enable before it can be triggered.
ReleaseNotes
Macro Author: @JMichaelTX
This is just an example written in response to the below KM Forum Topic. You will need to use as an example and/or change to meet your workflow automation needs.
MACRO SETUP
- Carefully review the Release Notes and the Macro Actions
- Make sure you understand what the Macro will do.
- You are responsible for running the Macro, not me.
