-3

I would like to create a regex which can match the following pattern

HR060178 RGP LUKA RIJEKA 30.09.2022 09:42:52 22HR060178U0078350MRN

to be specific the date which comes after text LUKA RIJEKA and the MRN number starting with 22 The screenshot is of another problem where in the highlighted numbers need to be extracted.

  • Please read [ask] and [mcve]. – TDG Oct 21 '22 at 09:43
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Oct 21 '22 at 09:53

1 Answers1

0

since you only provided this one sample, its diffucult to test edge cases and fine tune the regex, but the following should give you a good starting point:

((?<=LUKA\sRIJEKA\s)\d\d\.\d\d\.\d\d\d\d)|((?<=\sLUKA\sRIJEKA\s\d\d\.\d\d\.\d\d\d\d\s\d\d:\d\d:\d\d\s)22[^\s]+?MRN)

i have split your problem into two match groups, one that looks for the date and one which looks for the MRN.

i would advice you to read through this article: Regex lookahead, lookbehind and atomic groups. since the solution heavily relies on lookaheads. for creating and testing regexes i would recommend you to use one of the many websites which come up when you search for "regex online"

A-New-User
  • 61
  • 3