RegExe Reqtify : capturing multilines Requirements

Viewed 103

I'm new here and I'm also a beginner in regex.

I'm using Reqtify to match and capture Requirements from a PDF file.

Here the example of the file content:

**Requirement1** 

Text of the first requirement bla bla 

Second line of the first requirement.

**Requirement2** 

Text of the second requirement, no second line

**Heading 2[Distributed]**

**Requirement3** 
Text of the third requirement

Second line of the third requirement 

Third line of the third requirement 

**Heading 1[Distributed]**

**Requirement4**
 
Text of the 4th requirement

Second line of the 4th requirement 

Third line of the 4th requirement 

**Heading3[Distributed]**
[...]

Here what i want for the Requirement3 for example :

Text of the third requirement
Second line of the third requirement 
Third line of the third requirement 

As can you see the file mixes requirements and different heading (1,2,3 etc).

My first idea was to capture each requirement until the line which ends with *"]".

So my regex pattern is:

(^Requirement\d+).*$\n(\s\S]*?)^.*Distributed\]$ 

But it doesn't work well (see picture below).

enter image description here

My second idea is to have different end of the multiline, something like this:

(^Requirement\d+).*$\n(\s\S]*?)**^.*Distributed\]$|^Heading\d+**

But it doesn't work at all, i know that the regex syntax isn't right.

Can someone, please, help with the two ideas?

Thank you for your time.

Also, if you have documentation about regex in Reqtify I would love to read it.

PS: I use regex101 to test my expression.


Thank to @GreyMurav I can capture what I want. However I noticed that in the file, in each page there are a header and a footer, so in some requirement they are captured.

The header its like this :

'#TABLE

'#TR|1 bla bla bla bla

'#TR[1...................... Distributed|5 page 5/102

SO you can have something like this : Requirements 5

First line of the requirement

*#TABLE

#TR|1 bla bla bla bla

#TR[1...................... Distributed|5 page 5/102*

The rest of the requirement bla bla.

Here what I tried :

  1. add a non-capturing group ''' (?:^#TABLE\nTR.*\n#TR.Distributed.$) ''' I tried to place it everywhere but It doesnt work.
  2. In Reqtify you can apply a sub-exopression to a group. But it doesn't work eather.

How can I solve this problem?

Thank you for your time.

1 Answers

You can use a pattern that captures all lines after matching Requirement stops matching until a line start with Requirement or contains [Distributed]

^Requirement\d+\s*\n((?:(?!^Requirement\d|.*?\[Distributed]).*(?:\n|$))*)

The pattern matches:

  • ^ Start of string
  • Requirement\d+\s*\n
  • ( Capture group 1
    • (?: Non capture group
      • (?!^Requirement\d|.*?\[Distributed]) Assert that the string does not start with Requirement and a digit and does not contain [Distributed]
      • .* Match the whole line
      • (?:\n|$) Match a newline or assert the end of the string
    • )* Close the non capture group an optionally repeat to match all lines
  • ) Close group 1

See a regex101 demo

Related