How do I match any line containing #Test and also all next lines from it as long they start with:
- any amount of space followed by a
;
Example:
1. ; #Test
2. ; bbbb
3.
4. ; #Test
5.
6. ; aaa
Line 1 and 2 are one match, line 4 another match
This is what i got atm:
\s*(#Test).*(\s*;.*)*
https://regex101.com/r/HvPAxt/1
My current doubt is how to stop matching when an empty line is found.
Example2:
1. ; #Test
2. ; bbbb
3.
4. xxxx
5. ; #Test
6. yyyy
7.
8. ; #Test
9.
10. ; bbb
Line 1 and 2 are one match
Line 5 another match
Line 8 is another match.
>Solution :
The problem with your RE is that \s also matches newlines.
You need to use a regular expression that is explicit about newlines, since you have specific requirements about them.
So I would use [ \t]* to match spaces and tabs, instead of \s*:
[ \t]*(#Test).*(\n[ \t]*;.*)*
PS: Make sure you don’t use the s option (single line) because then . will start matching the newline character too.