I am having a dataset that looks like
I(0,123...789){
A(0,567...999){.......n=Marc.....}
B(2,655...265){..................}
C(3,993...333){..................}
M(8,635...254){.................;}
}
O(0,345...789){
A(0,567...999){.......n=Marc.....}
B(2,876...775){..................}
C(3,993...549){..................}
M(8,354...987){.................;}
}
I(0,987...764){
A(0,567...999){.......n=Marc.....}
B(2,543...265){..................}
C(7,998...933){..................}
M(8,645...284){.................;}
}
B(0,123...789){
.......
}
I(0,987...764){
A(0,567...999){.......n=John.....}
B(2,543...265){..................}
C(7,998...933){..................}
M(8,645...284){.................;}
}
I am trying to return all I "sections" so starting from "I" until the closing tag that comes after the ;} but only if the "I" section contains n=Marc.
So far I came with
^([I]\(.*\){.*n=Marc.*^[M]\(.*;}.)}
https://regex101.com/r/VSuZh5/1
However in some cases, when data has a pattern like
I(0,123...789){
A(0,567...999){.......n=Marc.....}
B(2,655...265){..................}
C(3,993...333){..................}
M(8,635...254){.................;}
}
O(0,345...789){
A(0,567...999){.......n=Marc.....}
B(2,876...775){..................}
C(3,993...549){..................}
M(8,354...987){.................;}
}
The regular expression returns both the I and O section. Is there a way to make sure it always return the I section?
- apologies for the dataset, it's huge and contains a lot of sensitive data which I can't make public.*