Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

REGEX to cover just first match from all

I have this type of regex

\b[0-9][0-9][0-9][0-9][0-9]\b

It’s not complete, this will match me many examples of 5 digit but I need just first and one match from this structure:

Reference Number            WW  
30966                     CFUN22       098765334    
30967                     CFUN22       098765335

30968                     CFUN22       098765336        
30969                     CFUN22    098765337

In this case I need just "30966" , not 30967,30968 and so on…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I tried to do

\b[0-9][0-9][0-9][0-9][0-9]\b

>Solution :

You can use a positive lookbehind to make sure that you’re grabbing the first 5-digit number after the word "Comments":

(?<=Comments\n)\d{5}\b

https://regex101.com/r/pZLj4K/1

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading