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

regular expression

Need some help(
I have a string:

:01:Test1:1111:02:Test2:2222:03:Test3:3333

I need to separate it with reg expression like this:

:01:Test1:1111
:02:Test2:2222
:03:Test3:3333

I have an expression and it works great, if all parameters has values:

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

:.+?:.+?:[^:]+

But if I have a parameter with null value, like:

:01:Test1:1111:02:Test2::03:Test3:3333

I’ll get this result:

:01:Test1:1111
:02:Test2::03

But I need:

:01:Test1:1111
:02:Test2:
:03:Test3:3333

How should I change my regexp to fix this situation and get correct result for each situation?

>Solution :

The issue here is that + is one to unlimited times whereas you’re looking for zero to unlimited times, and greedy.

Try:

:.+?:.+?:[^:]*+

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