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: match several not obligated lines

I’m sorry for not very clear title(

Let me explain the details below.

I have a file with next lines:

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

...
09-05-2023 13:15. Feature. Test ticket. #OW72-59

  New feature description.

  Second line of new feature.

09-05-2023 13:15. Bug. Weird bug is here. #OW72-58
...

Every item has mandatory fixed part (09-05-2023 13:15. Feature. Test ticket. #OW72-59, for example) and not mandatory part ( New feature description. Second line of new feature., for example). Not mandatory part may be multiline and always formatted with two leading spaces on every line. But I think I can this format if it will help.

My current regex (https://regex101.com/r/HTdvjN/1) matches regular part very well. But I can’t match partial part correctly.

I can change the format of the file if necessary.

Thanks.

enter image description here

>Solution :

You may use this regex with your specifications:

(?'date'\d+-\d+-\d+\s*\d*:?\d+)\. (?'tag'\w+)\. (?'desc'\w.*)\. #(?<issueId>\w+-\d+)(?'feature'(?:[\r\n]+  .*)*)

RegEx Demo

Important change is this part to capture multiline :

(?'feature'(?:[\r\n]+  .*)*)

This pattern matches line break followed by a line that starts with 2 spaces. Repeat this group 0 or more times to allow matching empty text or multiple lines.

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