regex pattern to get date after a particular text and a combination of word-number string ending with text MRN
Question:
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.
Answers:
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:
((?<=LUKAsRIJEKAs)dd.dd.dddd)|((?<=sLUKAsRIJEKAsdd.dd.ddddsdd:dd:dds)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"
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.
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:
((?<=LUKAsRIJEKAs)dd.dd.dddd)|((?<=sLUKAsRIJEKAsdd.dd.ddddsdd:dd:dds)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"