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:

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 ( matches regular part very well. But I can’t match partial part correctly.

I can change the format of the file if necessary.


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.

Leave a Reply