Regex - Retrieving Preformatted File Property

1

The idea is to develop a tool that selects fields from a preformatted file according to a specific schema:

Schema:

1.   
[Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris efficitur 
laoreet gravida. Nunc lacinia elit in nulla ultrices viverra eget eget 
massa. Phasellus suscipit pharetra ex non euismod. 
Sed mollis laoreet odio id blandit. Maecenas vel orci sed lacus commodo 
commodo et a mauris.


{asd123ASD/asd123ASD/a1A/a1A/a1A -:_ }

]

Basically a text file with an index and a content between [ ] that highlights a non-delimited string and a command block delimited by { } .

The goal is to capture data in groups. Ex .: Indexes, Texts Commands.

I saw that an "easy" way to solve is using RegEx .

So I came to this:

(\d{1}[[:punct:]]\s*\[){1}(.*\s*\{)(.*\s*\])

link

But it's only returning 2 matches where they should be 5.

Can anyone tell me where I'm wrong?

    
asked by anonymous 08.06.2017 / 22:13

1 answer

2

The problem is that some indexes are different from the first and fourth. Indexes 2,3 and 5 have spaces between the text, which regex can not match

Below the regex that can catch

(\d[[:punct:]])\s*\[([a-zA-Z\s[[:punct:]]*)\s*{(.*)}\s*\]

See it working link

    
09.06.2017 / 03:57